Class: SiteValidator::Sitemap

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

Overview

A sitemap has an URL, and holds a collection of pages to be validated

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, max_pages = 100) ⇒ Sitemap

Returns a new instance of Sitemap.



13
14
15
16
# File 'lib/site_validator/sitemap.rb', line 13

def initialize(url, max_pages = 100)
  @url       = url
  @max_pages = max_pages
end

Instance Attribute Details

#max_pagesObject

Returns the value of attribute max_pages.



11
12
13
# File 'lib/site_validator/sitemap.rb', line 11

def max_pages
  @max_pages
end

#urlObject

Returns the value of attribute url.



11
12
13
# File 'lib/site_validator/sitemap.rb', line 11

def url
  @url
end

Instance Method Details

#errorsObject

Returns the combined validation errors of all the pages



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

def errors
  @errors ||= pages.map {|p| p.errors}.flatten.reject {|e| e.nil?}
end

#get_bindingObject

Returns the binding, needed to paint the ERB template when generating the HTML report (see site_validator/reporter.rb)



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

def get_binding
  binding
end

#pagesObject

Returns the first 250 unique URLs from the sitemap



20
21
22
# File 'lib/site_validator/sitemap.rb', line 20

def pages
  @pages ||= pages_in_sitemap.uniq {|p| p.url}[0..max_pages-1]
end

#warningsObject

Returns the combined validation warnings of all the pages



32
33
34
# File 'lib/site_validator/sitemap.rb', line 32

def warnings
  @warnings ||= pages.map {|p| p.warnings}.flatten.reject {|e| e.nil?}
end