Class: Govspeak::HtmlValidator
- Inherits:
-
Object
- Object
- Govspeak::HtmlValidator
- Defined in:
- lib/govspeak/html_validator.rb
Instance Attribute Summary collapse
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #govspeak_to_html ⇒ Object
-
#initialize(string) ⇒ HtmlValidator
constructor
A new instance of HtmlValidator.
- #invalid? ⇒ Boolean
-
#normalise_html(html) ⇒ Object
Make whitespace in html tags consistent.
- #valid? ⇒ Boolean
Constructor Details
#initialize(string) ⇒ HtmlValidator
Returns a new instance of HtmlValidator.
4 5 6 |
# File 'lib/govspeak/html_validator.rb', line 4 def initialize(string) @string = string end |
Instance Attribute Details
#string ⇒ Object (readonly)
Returns the value of attribute string.
2 3 4 |
# File 'lib/govspeak/html_validator.rb', line 2 def string @string end |
Instance Method Details
#govspeak_to_html ⇒ Object
23 24 25 |
# File 'lib/govspeak/html_validator.rb', line 23 def govspeak_to_html Govspeak::Document.new(string).to_html end |
#invalid? ⇒ Boolean
8 9 10 |
# File 'lib/govspeak/html_validator.rb', line 8 def invalid? !valid? end |
#normalise_html(html) ⇒ Object
Make whitespace in html tags consistent
19 20 21 |
# File 'lib/govspeak/html_validator.rb', line 19 def normalise_html(html) Nokogiri::HTML.parse(html).to_s end |
#valid? ⇒ Boolean
12 13 14 15 16 |
# File 'lib/govspeak/html_validator.rb', line 12 def valid? dirty_html = govspeak_to_html clean_html = Govspeak::HtmlSanitizer.new(dirty_html).sanitize normalise_html(dirty_html) == normalise_html(clean_html) end |