Class: SitemapReader
- Inherits:
-
Object
- Object
- SitemapReader
- Defined in:
- lib/sitemap_reader.rb
Overview
Parse sitemap
Example:
>> sm = SitemapReader.new('http://example.com/sitemap.xml').get_urls
=> [{:loc=>"http://example.com/page1", :lastmod=>"2013-08-18"},{:loc=>"http://example.com/page2", :lastmod=>nil}]
… or read from file like this:
>> sm = SitemapReader.new('./sitemap.xml').get_urls
=> [{:loc=>"http://example.com/page1", :lastmod=>"2013-08-18"},{:loc=>"http://example.com/page2", :lastmod=>nil}]
Instance Method Summary collapse
- #get_urls ⇒ Object
-
#initialize(file_or_url) ⇒ SitemapReader
constructor
Arguments: file_or_url: (String).
Constructor Details
#initialize(file_or_url) ⇒ SitemapReader
Arguments:
file_or_url: (String)
16 17 18 19 |
# File 'lib/sitemap_reader.rb', line 16 def initialize(file_or_url) @doc = Nokogiri::XML(get_sitemap(file_or_url)) @urls= get_urls end |
Instance Method Details
#get_urls ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/sitemap_reader.rb', line 21 def get_urls @doc.css('url').map do |u| loc = u.css('loc').first.content lastmod = u.css('lastmod').first.content unless u.css('lastmod').first.nil? {loc: loc, lastmod: lastmod} end end |