class Sanitize::Whitelist::Element

Attributes

attributes[R]
name[R]

Public Class Methods

new(name) click to toggle source
# File lib/sanitize/whitelist/element.rb, line 4
def initialize(name)
  @name = name
  @attributes = {}
  @allowed = true
end

Public Instance Methods

allow(attributes) click to toggle source
# File lib/sanitize/whitelist/element.rb, line 39
def allow(attributes)
  result = Array(attributes).map do |attr|
    @attributes[attr] = Sanitize::Whitelist::Attribute.new(attr)
  end
  result.size == 1 ? result.first : result
end
allow!() click to toggle source
# File lib/sanitize/whitelist/element.rb, line 23
def allow!
  @allowed = true
end
allowed?() click to toggle source
# File lib/sanitize/whitelist/element.rb, line 27
def allowed?
  !!@allowed
end
freeze() click to toggle source
Calls superclass method
# File lib/sanitize/whitelist/element.rb, line 10
def freeze
  super
  @attributes.values.each(&:freeze)
  @attributes.freeze
end
initialize_dup(original) click to toggle source
Calls superclass method
# File lib/sanitize/whitelist/element.rb, line 16
def initialize_dup(original)
  super
  @attributes = original.attributes.each_with_object({}) do |(key,value), result|
    result[key] = value.dup
  end
end
remove!() click to toggle source
# File lib/sanitize/whitelist/element.rb, line 31
def remove!
  @allowed = false
end
remove?() click to toggle source
# File lib/sanitize/whitelist/element.rb, line 35
def remove?
  !@allowed
end
to_hash() click to toggle source
# File lib/sanitize/whitelist/element.rb, line 46
def to_hash
  @attributes.empty? ? {} : {@name => @attributes.keys}
end
to_protocols_hash() click to toggle source
# File lib/sanitize/whitelist/element.rb, line 50
def to_protocols_hash
  @attributes.values.each_with_object({}) do |attribute, result|
    result.merge! @name => attribute.to_hash unless attribute.to_hash.empty?
  end
end