Class: PeekAView::Tools::HtmlValidator

Inherits:
Checker
  • Object
show all
Defined in:
lib/peek_a_view/tools/html_validator.rb

Instance Method Summary collapse

Methods inherited from Checker

#clean_reports

Constructor Details

#initialize(options) ⇒ HtmlValidator

Returns a new instance of HtmlValidator.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/peek_a_view/tools/html_validator.rb', line 9

def initialize(options)
  validator_uri = options.delete(:validator_uri)
  raise ArgumentError, "Option validator_uri must be specified" unless validator_uri
  super

  # Somehow the validator does not get this from the response
  charset = (options[:charset] || 'UTF-8').upcase

  @validator = W3CValidators::NuValidator.new(
    validator_uri: validator_uri,
    charset:       charset
  )
end

Instance Method Details

#check(uri) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/peek_a_view/tools/html_validator.rb', line 23

def check(uri)
  results = validate(uri)
  puts "Valid: #{results.is_valid?}"
  puts
  puts 'Errors'
  puts results.errors.map(&:message)
  puts
  puts 'Warnings'
  puts results.warnings.map(&:message)
  puts
end

#report(uri) ⇒ Object



35
36
37
38
# File 'lib/peek_a_view/tools/html_validator.rb', line 35

def report(uri)
  results = validate(uri)
  write_report(uri, results)
end