Class: ValidateWebsite::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/validate_website/validator.rb

Overview

Document validation from DTD or XSD (webservice for html5)

Constant Summary collapse

XHTML_PATH =
File.expand_path('../../../data/schemas', __FILE__)
HTML5_VALIDATOR_SERVICE =
'http://validator.w3.org/nu/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_doc, body, ignore = nil) ⇒ Validator

Returns a new instance of Validator.

Parameters:

  • original_doc (Nokogiri::HTML::Document)
  • The (String) —

    raw HTTP response body of the page

  • Errors (Regexp) —

    to ignore



18
19
20
21
22
23
24
25
# File 'lib/validate_website/validator.rb', line 18

def initialize(original_doc, body, ignore = nil)
  @original_doc = original_doc
  @body = body
  @ignore = ignore
  @dtd = @original_doc.internal_subset
  init_namespace(@dtd)
  @errors = []
end

Instance Attribute Details

#body ⇒ Object (readonly)

Returns the value of attribute body.



11
12
13
# File 'lib/validate_website/validator.rb', line 11

def body
  @body
end

#doc ⇒ Object (readonly)

Returns the value of attribute doc.



11
12
13
# File 'lib/validate_website/validator.rb', line 11

def doc
  @doc
end

#dtd ⇒ Object (readonly)

Returns the value of attribute dtd.



11
12
13
# File 'lib/validate_website/validator.rb', line 11

def dtd
  @dtd
end

#errors ⇒ Object (readonly)

Returns the value of attribute errors.



11
12
13
# File 'lib/validate_website/validator.rb', line 11

def errors
  @errors
end

#namespace ⇒ Object (readonly)

Returns the value of attribute namespace.



11
12
13
# File 'lib/validate_website/validator.rb', line 11

def namespace
  @namespace
end

#original_doc ⇒ Object (readonly)

Returns the value of attribute original_doc.



11
12
13
# File 'lib/validate_website/validator.rb', line 11

def original_doc
  @original_doc
end

#xsd ⇒ Object (readonly)

Returns the value of attribute xsd.



11
12
13
# File 'lib/validate_website/validator.rb', line 11

def xsd
  @xsd
end

Instance Method Details

#valid? ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/validate_website/validator.rb', line 29

def valid?
  errors.length == 0
end