Class: UHaul::Sitemap
- Inherits:
-
Object
- Object
- UHaul::Sitemap
- Defined in:
- lib/uhaul/sitemap.rb
Overview
A sitemap on uhaul.com.
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(links:) ⇒ Sitemap
constructor
A new instance of Sitemap.
- #inspect ⇒ String
Constructor Details
#initialize(links:) ⇒ Sitemap
Returns a new instance of Sitemap.
31 32 33 |
# File 'lib/uhaul/sitemap.rb', line 31 def initialize(links:) @links = links end |
Instance Attribute Details
Class Method Details
.fetch(url:) ⇒ Sitemap
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
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
#inspect ⇒ String
36 37 38 |
# File 'lib/uhaul/sitemap.rb', line 36 def inspect "#<#{self.class.name} links=#{@links.inspect}>" end |