Class: RSAC::Selectors::ChildSelector

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

Instance Attribute Summary collapse

Attributes inherited from Selector

#selector_type

Instance Method Summary collapse

Methods inherited from Selector

#eql?

Constructor Details

#initialize(parent, selector) ⇒ ChildSelector

Returns a new instance of ChildSelector.



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

def initialize(parent, selector)
  super(:SAC_CHILD_SELECTOR)

  @ancestor_selector = parent
  @simple_selector = selector
end

Instance Attribute Details

#ancestor_selectorObject Also known as: parent

Returns the value of attribute ancestor_selector.



4
5
6
# File 'lib/antisamy/csspool/rsac/sac/selectors/child_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/child_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/child_selector.rb', line 27

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

#hashObject



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

def hash
  [parent, selector].hash
end

#specificityObject



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

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

#to_cssObject



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

def to_css
  "#{parent.to_css} > #{selector.to_css}"
end

#to_xpath(prefix = true) ⇒ Object



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

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