Class: Html5Validator::Validator
- Inherits:
-
Object
- Object
- Html5Validator::Validator
- Defined in:
- lib/html5_validator/validator.rb
Constant Summary collapse
- BASE_URI =
'http://validator.nu'
- HEADERS =
{ 'Content-Type' => 'text/html; charset=utf-8', 'Content-Encoding' => 'UTF-8' }
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(proxy = nil) ⇒ Validator
constructor
A new instance of Validator.
- #inspect ⇒ Object
- #valid? ⇒ Boolean
-
#validate_file(file) ⇒ Object
TODO - Flesh out the file upload method Validate the markup of a file.
-
#validate_text(text) ⇒ Object
Validate the markup of a String.
-
#validate_uri(uri) ⇒ Object
Validate the markup of a URI.
Constructor Details
#initialize(proxy = nil) ⇒ Validator
Returns a new instance of Validator.
10 11 12 |
# File 'lib/html5_validator/validator.rb', line 10 def initialize(proxy = nil) RestClient.proxy = proxy unless proxy.nil? end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/html5_validator/validator.rb', line 8 def errors @errors end |
Instance Method Details
#inspect ⇒ Object
33 34 35 36 37 |
# File 'lib/html5_validator/validator.rb', line 33 def inspect @errors.map do |err| "- Error: #{err['message']}" end.join("\n") end |
#valid? ⇒ Boolean
39 40 41 |
# File 'lib/html5_validator/validator.rb', line 39 def valid? @errors.length == 0 end |
#validate_file(file) ⇒ Object
TODO - Flesh out the file upload method Validate the markup of a file
30 31 |
# File 'lib/html5_validator/validator.rb', line 30 def validate_file(file) end |
#validate_text(text) ⇒ Object
Validate the markup of a String
15 16 17 18 19 |
# File 'lib/html5_validator/validator.rb', line 15 def validate_text(text) response = RestClient.post "#{BASE_URI}/?out=json", text, HEADERS @json = JSON.parse(response.body) @errors = retrieve_errors end |
#validate_uri(uri) ⇒ Object
Validate the markup of a URI
22 23 24 25 26 |
# File 'lib/html5_validator/validator.rb', line 22 def validate_uri(uri) response = RestClient.get BASE_URI, :params => { :doc => uri, :out => 'json' } @json = JSON.parse(response.body) @errors = retrieve_errors end |