Class: NodeQuery::Compiler::Regexp
- Inherits:
-
Object
- Object
- NodeQuery::Compiler::Regexp
- Includes:
- Comparable
- Defined in:
- lib/node_query/compiler/regexp.rb
Overview
Regexp represents a ruby regexp value.
Constant Summary
Constants included from Comparable
Comparable::ARRAY_VALID_OPERATORS, Comparable::NUMBER_VALID_OPERATORS, Comparable::REGEXP_VALID_OPERATORS, Comparable::SIMPLE_VALID_OPERATORS, Comparable::STRING_VALID_OPERATORS
Instance Method Summary collapse
-
#initialize(value:, adapter:) ⇒ Regexp
constructor
Initialize a Regexp.
-
#match?(node, _base_node, operator = '=~') ⇒ Boolean
Check if the regexp value matches the node value.
- #to_s ⇒ Object
-
#valid_operators ⇒ Array
Get valid operators.
Methods included from Comparable
#actual_value, #expected_value, #is_equal?, #valid_operator?
Constructor Details
#initialize(value:, adapter:) ⇒ Regexp
Initialize a Regexp.
11 12 13 14 |
# File 'lib/node_query/compiler/regexp.rb', line 11 def initialize(value:, adapter:) @value = value @adapter = adapter end |
Instance Method Details
#match?(node, _base_node, operator = '=~') ⇒ Boolean
Check if the regexp value matches the node value.
21 22 23 24 25 26 27 28 29 |
# File 'lib/node_query/compiler/regexp.rb', line 21 def match?(node, _base_node, operator = '=~') match = if @adapter.is_node?(node) @value.match(@adapter.get_source(node)) else @value.match(node.to_s) end operator == '=~' ? match : !match end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/node_query/compiler/regexp.rb', line 37 def to_s @value.to_s end |
#valid_operators ⇒ Array
Get valid operators.
33 34 35 |
# File 'lib/node_query/compiler/regexp.rb', line 33 def valid_operators REGEXP_VALID_OPERATORS end |