Class: StringTools::Sanitizer::IframeNormalizer

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

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ IframeNormalizer

Returns a new instance of IframeNormalizer.



208
209
210
# File 'lib/string_tools.rb', line 208

def initialize(attributes)
  @attributes = attributes
end

Instance Method Details

#call(env) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/string_tools.rb', line 212

def call(env)
  node = env[:node]

  return unless node.name == 'iframe'

  unless node[:src] =~ %r{^(http|https):?\/\/(www\.)?youtube?\.com\/}
    node.unlink
    return
  end

  Sanitize.node!(env[:node], elements: %w(iframe), attributes: {'iframe' => @attributes})
end