Class: REXML::CSSSelector::Queries::OnlyChildQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/rexml/css_selector/queries/only_child_query.rb

Instance Method Summary collapse

Constructor Details

#initialize(cont:) ⇒ OnlyChildQuery

Returns a new instance of OnlyChildQuery.



7
8
9
# File 'lib/rexml/css_selector/queries/only_child_query.rb', line 7

def initialize(cont:)
  @cont = cont
end

Instance Method Details

#call(node, context) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/rexml/css_selector/queries/only_child_query.rb', line 11

def call(node, context)
  return false unless context.adapter.element?(node)

  parent = context.adapter.get_parent_node(node)
  return false unless parent

  children = context.adapter.get_children_elements(parent)
  children.size == 1 && @cont.call(node, context)
end