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:) ⇒ 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:) ⇒ Regexp
Initialize a Regexp.
10 11 12 |
# File 'lib/node_query/compiler/regexp.rb', line 10 def initialize(value:) @value = value end |
Instance Method Details
#match?(node, _base_node, operator = '=~') ⇒ Boolean
Check if the regexp value matches the node value.
19 20 21 22 23 24 25 26 27 |
# File 'lib/node_query/compiler/regexp.rb', line 19 def match?(node, _base_node, operator = '=~') match = if NodeQuery.adapter.is_node?(node) @value.match(NodeQuery.adapter.get_source(node)) else @value.match(node.to_s) end operator == '=~' ? match : !match end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/node_query/compiler/regexp.rb', line 35 def to_s @value.to_s end |
#valid_operators ⇒ Array
Get valid operators.
31 32 33 |
# File 'lib/node_query/compiler/regexp.rb', line 31 def valid_operators REGEXP_VALID_OPERATORS end |