Class: W3CValidators::NuValidator
- Defined in:
- lib/w3c_validators/nu_validator.rb
Constant Summary collapse
- MARKUP_VALIDATOR_URI =
'http://validator.nu/'
Constants inherited from Validator
Validator::HEAD_ERROR_COUNT_HEADER, Validator::HEAD_STATUS_HEADER, Validator::SOAP_OUTPUT_PARAM, Validator::USER_AGENT, Validator::VERSION
Instance Attribute Summary
Attributes inherited from Validator
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ NuValidator
constructor
Create a new instance of the NuValidator.
-
#validate_file(file) ⇒ Object
Validate the markup of a local file.
-
#validate_text(text) ⇒ Object
Validate the markup of a string.
-
#validate_uri(uri) ⇒ Object
Validate the markup of an URI.
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')
).
16 17 18 19 20 21 22 23 24 |
# File 'lib/w3c_validators/nu_validator.rb', line 16 def initialize( = {}) if [:validator_uri] @validator_uri = URI.parse([:validator_uri]) .delete([:validator_uri]) else @validator_uri = URI.parse(MARKUP_VALIDATOR_URI) end super() end |
Instance Method Details
#validate_file(file) ⇒ Object
Validate the markup of a local file.
file_path
may be either the fully-expanded path to the file or an IO object (like File).
Returns W3CValidators::Results.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/w3c_validators/nu_validator.rb', line 48 def validate_file(file) if file.respond_to? :read src = file.read file_path = file.path ||= nil else src = read_local_file(file) file_path = file end return validate({:file => src, :file_path => file_path}) end |
#validate_text(text) ⇒ Object
Validate the markup of a string.
Returns W3CValidators::Results.
38 39 40 |
# File 'lib/w3c_validators/nu_validator.rb', line 38 def validate_text(text) return validate({:content => text}) end |
#validate_uri(uri) ⇒ Object
Validate the markup of an URI.
Returns W3CValidators::Results.
30 31 32 |
# File 'lib/w3c_validators/nu_validator.rb', line 30 def validate_uri(uri) return validate({:doc => uri}) end |