Class: Synvert::Core::NodeQuery::Compiler::BasicSelector
- Inherits:
-
Object
- Object
- Synvert::Core::NodeQuery::Compiler::BasicSelector
- Defined in:
- lib/synvert/core/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) ⇒ BasicSelector
constructor
Initialize a BasicSelector.
-
#match?(node, _operator = '==') ⇒ Boolean
Check if node matches the selector.
- #to_s ⇒ Object
Constructor Details
#initialize(node_type:, attribute_list: nil) ⇒ BasicSelector
Initialize a BasicSelector.
9 10 11 12 |
# File 'lib/synvert/core/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, _operator = '==') ⇒ Boolean
Check if node matches the selector.
16 17 18 19 20 |
# File 'lib/synvert/core/node_query/compiler/basic_selector.rb', line 16 def match?(node, _operator = '==') return false unless node @node_type.to_sym == node.type && (!@attribute_list || @attribute_list.match?(node)) end |
#to_s ⇒ Object
22 23 24 25 26 |
# File 'lib/synvert/core/node_query/compiler/basic_selector.rb', line 22 def to_s result = [".#{@node_type}"] result << @attribute_list.to_s if @attribute_list result.join('') end |