Class: CSS::SAC::Selectors::ConditionalSelector
- Inherits:
-
SimpleSelector
- Object
- Selector
- SimpleSelector
- CSS::SAC::Selectors::ConditionalSelector
- Defined in:
- lib/css/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
Methods included from Visitable
Constructor Details
#initialize(selector, condition) ⇒ ConditionalSelector
Returns a new instance of ConditionalSelector.
10 11 12 13 14 15 |
# File 'lib/css/sac/selectors/conditional_selector.rb', line 10 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.
7 8 9 |
# File 'lib/css/sac/selectors/conditional_selector.rb', line 7 def condition @condition end |
#simple_selector ⇒ Object Also known as: selector
Returns the value of attribute simple_selector.
7 8 9 |
# File 'lib/css/sac/selectors/conditional_selector.rb', line 7 def simple_selector @simple_selector end |
Instance Method Details
#==(other) ⇒ Object
37 38 39 |
# File 'lib/css/sac/selectors/conditional_selector.rb', line 37 def ==(other) super && condition == other.condition && selector == other.selector end |
#hash ⇒ Object
41 42 43 |
# File 'lib/css/sac/selectors/conditional_selector.rb', line 41 def hash [condition, selector].hash end |
#specificity ⇒ Object
32 33 34 35 |
# File 'lib/css/sac/selectors/conditional_selector.rb', line 32 def specificity (selector ? selector.specificity : 0) + (condition ? condition.specificity : 0) end |
#to_css ⇒ Object
17 18 19 20 21 |
# File 'lib/css/sac/selectors/conditional_selector.rb', line 17 def to_css [selector, condition].map { |x| x ? x.to_css : '' }.join('') end |
#to_xpath(prefix = true) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/css/sac/selectors/conditional_selector.rb', line 23 def to_xpath(prefix=true) atoms = [] atoms << "//" if prefix atoms << (selector ? selector.to_xpath(false) : "*") atoms << condition.to_xpath atoms.join("") end |