Class: Synvert::Core::NodeQuery::Compiler::Regexp
- Inherits:
-
Object
- Object
- Synvert::Core::NodeQuery::Compiler::Regexp
- Includes:
- Comparable
- Defined in:
- lib/synvert/core/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, operator = '=~') ⇒ Boolean
Check if the regexp value matches the node value.
- #to_s ⇒ Object
-
#valid_operators ⇒ Object
Get valid operators.
Methods included from Comparable
#actual_value, #expected_value, #valid_operator?
Constructor Details
#initialize(value:) ⇒ Regexp
Initialize a Regexp.
10 11 12 |
# File 'lib/synvert/core/node_query/compiler/regexp.rb', line 10 def initialize(value:) @value = value end |
Instance Method Details
#match?(node, operator = '=~') ⇒ Boolean
Check if the regexp value matches the node value.
18 19 20 21 22 23 24 25 26 |
# File 'lib/synvert/core/node_query/compiler/regexp.rb', line 18 def match?(node, operator = '=~') match = if node.is_a?(::Parser::AST::Node) @value.match(node.to_source) else @value.match(node.to_s) end operator == '=~' ? match : !match end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/synvert/core/node_query/compiler/regexp.rb', line 33 def to_s @value.to_s end |
#valid_operators ⇒ Object
Get valid operators.
29 30 31 |
# File 'lib/synvert/core/node_query/compiler/regexp.rb', line 29 def valid_operators REGEXP_VALID_OPERATORS end |