Class: HtmlMockup::W3CValidator

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#errorsObject (readonly)

Returns the value of attribute errors.



13
14
15
# File 'lib/html_mockup/w3c_validator.rb', line 13

def errors
  @errors
end

#responseObject (readonly)

Returns the value of attribute response.



13
14
15
# File 'lib/html_mockup/w3c_validator.rb', line 13

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



13
14
15
# File 'lib/html_mockup/w3c_validator.rb', line 13

def status
  @status
end

#validObject (readonly)

Returns the value of attribute valid.



13
14
15
# File 'lib/html_mockup/w3c_validator.rb', line 13

def valid
  @valid
end

#warningsObject (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_uriObject



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
  options = {"output" => "json"}
  query,headers = build_post_query(options)
  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