Class: HtmlMockup::W3CValidator
- Inherits:
-
Object
- Object
- HtmlMockup::W3CValidator
- Defined in:
- lib/html_mockup/w3c_validator.rb
Defined Under Namespace
Classes: RequestError
Constant Summary collapse
- ValidationUri =
"http://validator.w3.org/check"
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#valid ⇒ Object
readonly
Returns the value of attribute valid.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(html) ⇒ W3CValidator
constructor
A new instance of W3CValidator.
- #validate! ⇒ Object
Constructor Details
#initialize(html) ⇒ W3CValidator
Returns a new instance of W3CValidator.
21 22 23 |
# File 'lib/html_mockup/w3c_validator.rb', line 21 def initialize(html) @html = html end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
13 14 15 |
# File 'lib/html_mockup/w3c_validator.rb', line 13 def errors @errors end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
13 14 15 |
# File 'lib/html_mockup/w3c_validator.rb', line 13 def response @response end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
13 14 15 |
# File 'lib/html_mockup/w3c_validator.rb', line 13 def status @status end |
#valid ⇒ Object (readonly)
Returns the value of attribute valid.
13 14 15 |
# File 'lib/html_mockup/w3c_validator.rb', line 13 def valid @valid end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
13 14 15 |
# File 'lib/html_mockup/w3c_validator.rb', line 13 def warnings @warnings end |
Class Method Details
.validation_uri ⇒ Object
16 17 18 |
# File 'lib/html_mockup/w3c_validator.rb', line 16 def validation_uri @uri ||= URI.parse(ValidationUri) end |
Instance Method Details
#validate! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/html_mockup/w3c_validator.rb', line 25 def validate! @status = @warnings = @errors = @response = @valid = nil = {"output" => "json"} query,headers = build_post_query() response = self.request(:post,self.class.validation_uri.path,query,headers) @status,@warnings,@errors = response["x-w3c-validator-status"],response["x-w3c-validator-warnings"].to_i,response["x-w3c-validator-errors"].to_i if @status == "Valid" && @warnings == 0 && @errors == 0 return @valid = true else begin @response = YAML.load(response.body) rescue end return (@valid = (@errros == 0)) end end |