Class: REXML::CSSSelector::Queries::NthChildQuery
- Inherits:
-
Object
- Object
- REXML::CSSSelector::Queries::NthChildQuery
- Defined in:
- lib/rexml/css_selector/queries/nth_child_query.rb
Instance Method Summary collapse
- #call(node, context) ⇒ Object
-
#initialize(cont:, a:, b:) ⇒ NthChildQuery
constructor
A new instance of NthChildQuery.
Constructor Details
#initialize(cont:, a:, b:) ⇒ NthChildQuery
Returns a new instance of NthChildQuery.
7 8 9 10 11 |
# File 'lib/rexml/css_selector/queries/nth_child_query.rb', line 7 def initialize(cont:, a:, b:) @cont = cont @a = a @b = b end |
Instance Method Details
#call(node, context) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rexml/css_selector/queries/nth_child_query.rb', line 13 def call(node, context) return false unless context.adapter.element?(node) parent = context.adapter.get_parent_node(node) return false unless parent index = context.adapter.get_element_index(parent, node) return false unless index index += 1 if @a.zero? index == @b && @cont.call(node, context) else ((index - @b) % @a).zero? && (index - @b) / @a >= 0 && @cont.call(node, context) end end |