Class: W3CValidators::NuValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/w3c_validators/nu_validator.rb

Constant Summary collapse

MARKUP_VALIDATOR_URI =
'https://validator.w3.org/nu/'

Constants inherited from Validator

Validator::HEAD_ERROR_COUNT_HEADER, Validator::HEAD_STATUS_HEADER, Validator::SOAP_OUTPUT_PARAM, Validator::USER_AGENT, Validator::USE_NEW_EXCEPTION

Instance Attribute Summary

Attributes inherited from Validator

#results, #validator_uri

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ NuValidator

Create a new instance of the NuValidator.

Options

The options hash allows you to set request parameters (see wiki.whatwg.org/wiki/Validator.nu_Common_Input_Parameters) quickly. Request parameters can also be set using set_charset! and set_doctype!.

You can pass in your own validator’s URI (i.e. NuValidator.new(:validator_uri => 'http://localhost/check')).

See Validator#new for proxy server options.



18
19
20
21
22
23
24
25
26
27
# File 'lib/w3c_validators/nu_validator.rb', line 18

def initialize(options = {})
  options[:parser] = 'html'
  if options[:validator_uri]
    @validator_uri = URI.parse(options[:validator_uri])
    options.delete(options[:validator_uri])
  else
    @validator_uri = URI.parse(MARKUP_VALIDATOR_URI)
  end
  super(options)
end

Instance Method Details

#validate_file(file) ⇒ Object

Validate the markup of a local file.

file may be either the fully-expanded path to the file or an IO object (like File).

Returns W3CValidators::Results.



51
52
53
54
55
56
57
58
59
# File 'lib/w3c_validators/nu_validator.rb', line 51

def validate_file(file)
  if file.respond_to? :read
    src = file.read
  else
    src = read_local_file(file)
  end 

  return validate_text(src)
end

#validate_text(text) ⇒ Object

Validate the markup of a string.

Returns W3CValidators::Results.



41
42
43
# File 'lib/w3c_validators/nu_validator.rb', line 41

def validate_text(text)
  return validate({:content => text})
end

#validate_uri(uri) ⇒ Object

Validate the markup of an URI.

Returns W3CValidators::Results.



33
34
35
# File 'lib/w3c_validators/nu_validator.rb', line 33

def validate_uri(uri)
  return validate({:doc => uri})
end