Class: Govspeak::HtmlValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/govspeak/html_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(govspeak_string, options = {}) ⇒ HtmlValidator

Returns a new instance of HtmlValidator.



4
5
6
7
# File 'lib/govspeak/html_validator.rb', line 4

def initialize(govspeak_string, options = {})
  @govspeak_string = govspeak_string.dup.force_encoding(Encoding::UTF_8)
  @allowed_image_hosts = options[:allowed_image_hosts]
end

Instance Attribute Details

#govspeak_stringObject (readonly)

Returns the value of attribute govspeak_string.



2
3
4
# File 'lib/govspeak/html_validator.rb', line 2

def govspeak_string
  @govspeak_string
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/govspeak/html_validator.rb', line 9

def invalid?
  !valid?
end

#valid?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/govspeak/html_validator.rb', line 13

def valid?
  dirty_html = govspeak_to_html(sanitize: false)
  clean_html = govspeak_to_html(sanitize: true)
  normalise_html(dirty_html) == normalise_html(clean_html)
end