Class: NodeQuery::Compiler::BasicSelector
- Inherits:
-
Object
- Object
- NodeQuery::Compiler::BasicSelector
- 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
-
#initialize(node_type:, attribute_list: nil, adapter:) ⇒ BasicSelector
constructor
Initialize a BasicSelector.
-
#match?(node, base_node, _operator = '=') ⇒ Boolean
Check if node matches the selector.
- #to_s ⇒ Object
Constructor Details
#initialize(node_type:, attribute_list: nil, adapter:) ⇒ BasicSelector
Initialize a BasicSelector.
10 11 12 13 14 |
# File 'lib/node_query/compiler/basic_selector.rb', line 10 def initialize(node_type:, attribute_list: nil, adapter:) @node_type = node_type @attribute_list = attribute_list @adapter = adapter end |
Instance Method Details
#match?(node, base_node, _operator = '=') ⇒ Boolean
Check if node matches the selector.
20 21 22 23 24 25 26 27 |
# File 'lib/node_query/compiler/basic_selector.rb', line 20 def match?(node, base_node, _operator = '=') return false unless node @node_type.to_sym == @adapter.get_node_type(node) && (!@attribute_list || @attribute_list.match?( node, base_node )) end |
#to_s ⇒ Object
29 30 31 32 33 |
# File 'lib/node_query/compiler/basic_selector.rb', line 29 def to_s result = [".#{@node_type}"] result << @attribute_list.to_s if @attribute_list result.join('') end |