Class: Html5Validator::Validator
- Inherits:
-
Object
- Object
- Html5Validator::Validator
- Defined in:
- lib/html5_validator.rb
Constant Summary collapse
- BASE_URI =
'http://html5.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.
15 16 17 |
# File 'lib/html5_validator.rb', line 15 def initialize(proxy = nil) RestClient.proxy = proxy unless proxy.nil? end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
13 14 15 |
# File 'lib/html5_validator.rb', line 13 def errors @errors end |
Instance Method Details
#inspect ⇒ Object
38 39 40 41 42 |
# File 'lib/html5_validator.rb', line 38 def inspect @errors.map do |err| "- Error: #{err['message']}" end.join("\n") end |
#valid? ⇒ Boolean
44 45 46 |
# File 'lib/html5_validator.rb', line 44 def valid? @errors.length == 0 end |
#validate_file(file) ⇒ Object
TODO - Flesh out the file upload method Validate the markup of a file
35 36 |
# File 'lib/html5_validator.rb', line 35 def validate_file(file) end |
#validate_text(text) ⇒ Object
Validate the markup of a String
20 21 22 23 24 |
# File 'lib/html5_validator.rb', line 20 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
27 28 29 30 31 |
# File 'lib/html5_validator.rb', line 27 def validate_uri(uri) response = RestClient.get BASE_URI, :params => { :doc => uri, :out => 'json' } @json = JSON.parse(response.body) @errors = retrieve_errors end |