Class: RSAC::Selectors::ConditionalSelector

Inherits:
SimpleSelector show all
Defined in:
lib/antisamy/csspool/rsac/sac/selectors/conditional_selector.rb

Instance Attribute Summary collapse

Attributes inherited from Selector

#selector_type

Instance Method Summary collapse

Methods inherited from Selector

#eql?

Constructor Details

#initialize(selector, condition) ⇒ ConditionalSelector

Returns a new instance of ConditionalSelector.



7
8
9
10
11
12
# File 'lib/antisamy/csspool/rsac/sac/selectors/conditional_selector.rb', line 7

def initialize(selector, condition)
  super(:SAC_CONDITIONAL_SELECTOR)

  @condition = condition
  @simple_selector = selector
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



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

def condition
  @condition
end

#simple_selectorObject Also known as: selector

Returns the value of attribute simple_selector.



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

def simple_selector
  @simple_selector
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  super && condition == other.condition && selector == other.selector
end

#hashObject



40
41
42
# File 'lib/antisamy/csspool/rsac/sac/selectors/conditional_selector.rb', line 40

def hash
  [condition, selector].hash
end

#specificityObject



29
30
31
32
33
34
# File 'lib/antisamy/csspool/rsac/sac/selectors/conditional_selector.rb', line 29

def specificity
  (selector ? selector.specificity : ([0] * 4)).zip(
  (condition ? condition.specificity : ([0] * 4))).map { |x,y|
    x + y
  }
end

#to_cssObject



14
15
16
17
18
# File 'lib/antisamy/csspool/rsac/sac/selectors/conditional_selector.rb', line 14

def to_css
  [selector, condition].map { |x|
    x ? x.to_css : ''
  }.join('')
end

#to_xpath(prefix = true) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/antisamy/csspool/rsac/sac/selectors/conditional_selector.rb', line 20

def to_xpath(prefix=true)
  atoms = []
  atoms << "//" if prefix
  atoms << (selector ? selector.to_xpath(false) : "*")
  atoms << condition.to_xpath

  atoms.join("")
end