Class: CSS::SAC::Selectors::ConditionalSelector

Inherits:
SimpleSelector show all
Defined in:
lib/css/sac/selectors/conditional_selector.rb

Instance Attribute Summary collapse

Attributes inherited from Selector

#selector_type

Instance Method Summary collapse

Methods inherited from Selector

#=~, #eql?

Methods included from Visitable

#accept

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

#conditionObject

Returns the value of attribute condition.



7
8
9
# File 'lib/css/sac/selectors/conditional_selector.rb', line 7

def condition
  @condition
end

#simple_selectorObject 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

#hashObject



41
42
43
# File 'lib/css/sac/selectors/conditional_selector.rb', line 41

def hash
  [condition, selector].hash
end

#specificityObject



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_cssObject



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