Class: UHaul::Sitemap

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

Overview

A sitemap on uhaul.com.

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>)


31
32
33
# File 'lib/uhaul/sitemap.rb', line 31

def initialize(links:)
  @links = links
end

Instance Attribute Details

Returns:



8
9
10
# File 'lib/uhaul/sitemap.rb', line 8

def links
  @links
end

Class Method Details

.fetch(url:) ⇒ Sitemap

Parameters:

  • url (String)

Returns:



25
26
27
28
# File 'lib/uhaul/sitemap.rb', line 25

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

.parse(document:) ⇒ Sitemap

Parameters:

  • document (NokoGiri::XML::Document)

Returns:



13
14
15
16
17
18
19
20
# File 'lib/uhaul/sitemap.rb', line 13

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

  new(links: links.filter { |link| link.loc.match(%r{/Self-Storage-.*/\d+}) })
end

Instance Method Details

#inspectString

Returns:

  • (String)


36
37
38
# File 'lib/uhaul/sitemap.rb', line 36

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