Class: ValidateWebsite::Validator
- Inherits:
-
Object
- Object
- ValidateWebsite::Validator
- Extended by:
- ValidatorClassMethods
- Defined in:
- lib/validate_website/validator.rb
Overview
Document validation from DTD or XSD (webservice for html5)
Constant Summary collapse
- XHTML_SCHEMA_PATH =
File.('../../data/schemas', __dir__)
Class Attribute Summary collapse
-
.html5_validator_service_url ⇒ Object
Returns the value of attribute html5_validator_service_url.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#dtd ⇒ Object
readonly
Returns the value of attribute dtd.
-
#html5_validator ⇒ Object
readonly
Returns the value of attribute html5_validator.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#original_doc ⇒ Object
readonly
Returns the value of attribute original_doc.
Class Method Summary collapse
- .schema(namespace) ⇒ Object (also: xsd)
Instance Method Summary collapse
-
#errors ⇒ Array
Of errors.
-
#initialize(original_doc, body, ignore: nil, html5_validator: :tidy) ⇒ Validator
constructor
A new instance of Validator.
- #valid? ⇒ Boolean
Methods included from ValidatorClassMethods
Constructor Details
#initialize(original_doc, body, ignore: nil, html5_validator: :tidy) ⇒ Validator
Returns a new instance of Validator.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/validate_website/validator.rb', line 44 def initialize(original_doc, body, ignore: nil, html5_validator: :tidy) @errors = [] @document, @dtd_uri = nil @original_doc = original_doc @body = body @ignore = ignore @html5_validator = html5_validator @dtd = @original_doc.internal_subset @namespace = find_namespace(@dtd) end |
Class Attribute Details
.html5_validator_service_url ⇒ Object
Returns the value of attribute html5_validator_service_url.
20 21 22 |
# File 'lib/validate_website/validator.rb', line 20 def html5_validator_service_url @html5_validator_service_url end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
36 37 38 |
# File 'lib/validate_website/validator.rb', line 36 def body @body end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
36 37 38 |
# File 'lib/validate_website/validator.rb', line 36 def doc @doc end |
#dtd ⇒ Object (readonly)
Returns the value of attribute dtd.
36 37 38 |
# File 'lib/validate_website/validator.rb', line 36 def dtd @dtd end |
#html5_validator ⇒ Object (readonly)
Returns the value of attribute html5_validator.
36 37 38 |
# File 'lib/validate_website/validator.rb', line 36 def html5_validator @html5_validator end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
36 37 38 |
# File 'lib/validate_website/validator.rb', line 36 def namespace @namespace end |
#original_doc ⇒ Object (readonly)
Returns the value of attribute original_doc.
36 37 38 |
# File 'lib/validate_website/validator.rb', line 36 def original_doc @original_doc end |
Class Method Details
.schema(namespace) ⇒ Object Also known as: xsd
23 24 25 26 27 28 29 30 31 |
# File 'lib/validate_website/validator.rb', line 23 def schema(namespace) @mutex.synchronize do Dir.chdir(XHTML_SCHEMA_PATH) do if File.exist?("#{namespace}.xsd") Nokogiri::XML::Schema(File.read("#{namespace}.xsd")) end end end end |
Instance Method Details
#errors ⇒ Array
Returns of errors.
63 64 65 66 |
# File 'lib/validate_website/validator.rb', line 63 def errors @errors.map!(&:to_s) @ignore ? @errors.reject { |e| @ignore =~ e } : @errors end |
#valid? ⇒ Boolean
57 58 59 60 |
# File 'lib/validate_website/validator.rb', line 57 def valid? find_errors errors.empty? end |