Class: SiteHealth::Checkers::HTMLPage

Inherits:
Object
  • Object
show all
Defined in:
lib/site_health/checkers/html_page.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ HTMLPage

Returns a new instance of HTMLPage.

Parameters:

  • the (Spidr::Page)

    crawled page



11
12
13
14
# File 'lib/site_health/checkers/html_page.rb', line 11

def initialize(page)
  @page = page
  @url = page.url
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



8
9
10
# File 'lib/site_health/checkers/html_page.rb', line 8

def page
  @page
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/site_health/checkers/html_page.rb', line 8

def url
  @url
end

Class Method Details

.check(page) ⇒ Object



4
5
6
# File 'lib/site_health/checkers/html_page.rb', line 4

def self.check(page)
  new(page).check
end

Instance Method Details

#checkObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/site_health/checkers/html_page.rb', line 16

def check
  result = check_content

  HTMLJournal.new(
    url: url,
    page: page,
    missing_title: missing_title?,
    errors: result.errors.map { |e| W3CJournalBuilder.build(e) },
    warnings: result.warnings.map { |e| W3CJournalBuilder.build(e) }
  )
end

#check_contentW3CValidators::Results

Returns:

  • (W3CValidators::Results)

Raises:

  • (W3CValidators::ValidatorUnavailable)

    the service is offline or returns 400 Bad Request

See Also:



35
36
37
38
# File 'lib/site_health/checkers/html_page.rb', line 35

def check_content
  validator = W3CValidators::NuValidator.new
  validator.validate_uri(url)
end

#missing_title?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/site_health/checkers/html_page.rb', line 28

def missing_title?
  page.title.to_s.strip.empty?
end