Class: NodeQuery::Compiler::BasicSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/node_query/compiler/basic_selector.rb

Overview

BasicSelector used to match nodes, it combines by node type and/or attribute list.

Instance Method Summary collapse

Constructor Details

#initialize(node_type:, attribute_list: nil) ⇒ BasicSelector

Initialize a BasicSelector.

Parameters:



9
10
11
12
# File 'lib/node_query/compiler/basic_selector.rb', line 9

def initialize(node_type:, attribute_list: nil)
  @node_type = node_type
  @attribute_list = attribute_list
end

Instance Method Details

#match?(node, base_node, _operator = '=') ⇒ Boolean

Check if node matches the selector.

Parameters:

  • node (Node)

    the node

  • base_node (Node)

    the base node for evaluated value

Returns:



18
19
20
21
22
23
24
25
# File 'lib/node_query/compiler/basic_selector.rb', line 18

def match?(node, base_node, _operator = '=')
  return false unless node

  @node_type.to_sym == NodeQuery.adapter.get_node_type(node) && (!@attribute_list || @attribute_list.match?(
    node,
    base_node
  ))
end

#to_sObject



27
28
29
30
31
# File 'lib/node_query/compiler/basic_selector.rb', line 27

def to_s
  result = [".#{@node_type}"]
  result << @attribute_list.to_s if @attribute_list
  result.join('')
end