Class: RSAC::Selectors::ConditionalSelector
- Inherits:
-
SimpleSelector
- Object
- Selector
- SimpleSelector
- RSAC::Selectors::ConditionalSelector
- Defined in:
- lib/antisamy/csspool/rsac/sac/selectors/conditional_selector.rb
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#simple_selector ⇒ Object
(also: #selector)
Returns the value of attribute simple_selector.
Attributes inherited from Selector
Instance Method Summary collapse
- #==(other) ⇒ Object
- #hash ⇒ Object
-
#initialize(selector, condition) ⇒ ConditionalSelector
constructor
A new instance of ConditionalSelector.
- #specificity ⇒ Object
- #to_css ⇒ Object
- #to_xpath(prefix = true) ⇒ Object
Methods inherited from Selector
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
#condition ⇒ Object
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_selector ⇒ Object 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 |
#hash ⇒ Object
40 41 42 |
# File 'lib/antisamy/csspool/rsac/sac/selectors/conditional_selector.rb', line 40 def hash [condition, selector].hash end |
#specificity ⇒ Object
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_css ⇒ Object
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 |