Class: CubeSmart::Sitemap

Inherits:
Object
  • Object
show all
Defined in:
lib/cubesmart/sitemap.rb

Overview

A sitemap on cubesmart.com.

e.g. www.cubesmart.com/sitemap-facility.xml

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(links:) ⇒ Sitemap

Returns a new instance of Sitemap.

Parameters:

  • links (Array<Link>)


34
35
36
# File 'lib/cubesmart/sitemap.rb', line 34

def initialize(links:)
  @links = links
end

Instance Attribute Details

Returns:



10
11
12
# File 'lib/cubesmart/sitemap.rb', line 10

def links
  @links
end

Class Method Details

.fetch(url:) ⇒ Sitemap

Parameters:

  • url (String)

Returns:



28
29
30
31
# File 'lib/cubesmart/sitemap.rb', line 28

def self.fetch(url:)
  document = Crawler.xml(url:)
  parse(document:)
end

.parse(document:) ⇒ Sitemap

Parameters:

  • document (NokoGiri::XML::Document)

Returns:



15
16
17
18
19
20
21
22
23
# File 'lib/cubesmart/sitemap.rb', line 15

def self.parse(document:)
  links = document.xpath('//xmlns:url').map do |url|
    loc = url.at_xpath('xmlns:loc')&.text
    lastmod = url.at_xpath('xmlns:lastmod')&.text
    Link.new(loc:, lastmod:)
  end

  new(links: links)
end

Instance Method Details

#inspectString

Returns:

  • (String)


39
40
41
# File 'lib/cubesmart/sitemap.rb', line 39

def inspect
  "#<#{self.class.name} links=#{@links.inspect}>"
end