Class: RSAC::Selectors::DescendantSelector

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

Instance Attribute Summary collapse

Attributes inherited from Selector

#selector_type

Instance Method Summary collapse

Methods inherited from Selector

#eql?

Constructor Details

#initialize(ancestor, selector) ⇒ DescendantSelector

Returns a new instance of DescendantSelector.



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

def initialize(ancestor, selector)
  super(:SAC_DESCENDANT_SELECTOR)

  @ancestor_selector = ancestor
  @simple_selector = selector
end

Instance Attribute Details

#ancestor_selectorObject Also known as: ancestor

Returns the value of attribute ancestor_selector.



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

def ancestor_selector
  @ancestor_selector
end

#simple_selectorObject Also known as: selector

Returns the value of attribute simple_selector.



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

def simple_selector
  @simple_selector
end

Instance Method Details

#==(other) ⇒ Object



27
28
29
# File 'lib/antisamy/csspool/rsac/sac/selectors/descendant_selector.rb', line 27

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

#hashObject



31
32
33
# File 'lib/antisamy/csspool/rsac/sac/selectors/descendant_selector.rb', line 31

def hash
  [selector, ancestor].hash
end

#specificityObject



23
24
25
# File 'lib/antisamy/csspool/rsac/sac/selectors/descendant_selector.rb', line 23

def specificity
  ancestor.specificity.zip(selector.specificity).map { |x,y| x + y }
end

#to_cssObject



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

def to_css
  "#{ancestor.to_css} #{selector.to_css}"
end

#to_xpath(prefix = true) ⇒ Object



19
20
21
# File 'lib/antisamy/csspool/rsac/sac/selectors/descendant_selector.rb', line 19

def to_xpath(prefix=true)
  "#{ancestor.to_xpath(prefix)}//#{selector.to_xpath(false)}"
end