Class: RSAC::Conditions::AttributeCondition

Inherits:
Condition
  • Object
show all
Defined in:
lib/antisamy/csspool/rsac/sac/conditions/attribute_condition.rb

Instance Attribute Summary collapse

Attributes inherited from Condition

#condition_type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Condition

#eql?

Constructor Details

#initialize(local_name, value, specified, condition_type = :SAC_ATTRIBUTE_CONDITION) ⇒ AttributeCondition

Returns a new instance of AttributeCondition.



21
22
23
24
25
26
# File 'lib/antisamy/csspool/rsac/sac/conditions/attribute_condition.rb', line 21

def initialize(local_name, value, specified, condition_type=:SAC_ATTRIBUTE_CONDITION)
  super(condition_type)
  @local_name = local_name
  @value = value
  @specified = specified
end

Instance Attribute Details

#local_nameObject

Returns the value of attribute local_name.



4
5
6
# File 'lib/antisamy/csspool/rsac/sac/conditions/attribute_condition.rb', line 4

def local_name
  @local_name
end

#specifiedObject Also known as: specified?

Returns the value of attribute specified.



4
5
6
# File 'lib/antisamy/csspool/rsac/sac/conditions/attribute_condition.rb', line 4

def specified
  @specified
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/antisamy/csspool/rsac/sac/conditions/attribute_condition.rb', line 4

def value
  @value
end

Class Method Details

.build(name, raw) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/antisamy/csspool/rsac/sac/conditions/attribute_condition.rb', line 8

def build(name, raw)
  condition, value = raw
  case condition
  when "~="
    OneOfCondition.new(name, value)
  when "|="
    BeginHyphenCondition.new(name, value)
  else
    AttributeCondition.new(name, value, true)
  end
end

Instance Method Details

#==(other) ⇒ Object



40
41
42
43
# File 'lib/antisamy/csspool/rsac/sac/conditions/attribute_condition.rb', line 40

def ==(other)
  super && local_name == other.local_name && value == other.value &&
  specified == other.specified
end

#hashObject



45
46
47
# File 'lib/antisamy/csspool/rsac/sac/conditions/attribute_condition.rb', line 45

def hash
  [local_name, value, specified].hash
end

#specificityObject



36
37
38
# File 'lib/antisamy/csspool/rsac/sac/conditions/attribute_condition.rb', line 36

def specificity
  [0, 0, 1, 0]
end

#to_cssObject



28
29
30
# File 'lib/antisamy/csspool/rsac/sac/conditions/attribute_condition.rb', line 28

def to_css
  "[#{local_name}#{value && "=#{value}"}]"
end

#to_xpathObject



32
33
34
# File 'lib/antisamy/csspool/rsac/sac/conditions/attribute_condition.rb', line 32

def to_xpath
  "[@#{local_name}#{value && "='#{value}'"}]"
end