Skip to content

Instantly share code, notes, and snippets.

@afcapel
Created March 18, 2011 09:00
Show Gist options
  • Save afcapel/875792 to your computer and use it in GitHub Desktop.
Save afcapel/875792 to your computer and use it in GitHub Desktop.
##
# A sitemap has an URL, and holds a collection of pages to be validated
#
module W3Clove
require 'open-uri'
require 'nokogiri'
class Sitemap
attr_accessor :url
def initialize(url)
@url = url
end
def pages
@pages ||= pages_in_sitemap.uniq {|p| p.url}
end
def errors
pages.map {|p| p.errors}.flatten
end
def warnings
pages.map {|p| p.warnings}.flatten
end
private
def pages_in_sitemap
locations.map {|loc| W3Clove::Page.new(loc.text)}
end
def locations
Nokogiri::XML(doc).css('loc')
end
def doc
@doc ||= open(url)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment