Class: Hexp::CssSelector::Sequence
- Inherits:
-
Object
- Object
- Hexp::CssSelector::Sequence
- Includes:
- Members
- Defined in:
- lib/hexp/css_selector.rb
Overview
A single CSS sequence like ‘div span .foo’
Instance Attribute Summary
Attributes included from Members
Instance Method Summary collapse
-
#drop_head ⇒ Hexp::CssSelector::Sequence
private
Drop the first element of this Sequence.
-
#head_matches?(element) ⇒ true, false
private
Does the first element of this sequence match the element.
-
#matches_path?(path) ⇒ Boolean
Warning: Highly optimized cryptic code.
Methods included from Members
included, #initialize, #inspect
Instance Method Details
#drop_head ⇒ Hexp::CssSelector::Sequence
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Drop the first element of this Sequence
This returns a new Sequence, with one member less.
161 162 163 |
# File 'lib/hexp/css_selector.rb', line 161 def drop_head self.class.new(members.drop(1)) end |
#head_matches?(element) ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Does the first element of this sequence match the element
132 133 134 |
# File 'lib/hexp/css_selector.rb', line 132 def head_matches?(element) members.first.matches?(element) end |
#matches_path?(path) ⇒ Boolean
Warning: Highly optimized cryptic code
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/hexp/css_selector.rb', line 137 def matches_path?(path) return false if path.length < members.length return false unless members.last.matches?(path.last) path_idx = path.length - 2 mem_idx = members.length - 2 until path_idx < mem_idx || mem_idx == -1 if members[mem_idx].matches?(path[path_idx]) mem_idx -= 1 end path_idx -= 1 end mem_idx == -1 end |