Class: NodeQuery::Compiler::Identifier
- Inherits:
-
Object
- Object
- NodeQuery::Compiler::Identifier
- Includes:
- Comparable
- Defined in:
- lib/node_query/compiler/identifier.rb
Overview
Identifier represents a ruby identifier value. e.g. code is ‘class Synvert; end`, `Synvert` is an identifier.
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
-
#actual_value(node) ⇒ String|Array
Get the actual value.
-
#initialize(value:, adapter:) ⇒ Identifier
constructor
Initialize an Identifier.
- #to_s ⇒ Object
-
#valid_operators ⇒ Array
Get valid operators.
Methods included from Comparable
#expected_value, #is_equal?, #match?, #valid_operator?
Constructor Details
#initialize(value:, adapter:) ⇒ Identifier
Initialize an Identifier.
12 13 14 15 |
# File 'lib/node_query/compiler/identifier.rb', line 12 def initialize(value:, adapter:) @value = value @adapter = adapter end |
Instance Method Details
#actual_value(node) ⇒ String|Array
Get the actual value. If the node is a Node, return the node source code, if the node is an Array, return the array of each element’s actual value, otherwise, return the String value.
23 24 25 26 27 28 29 30 31 |
# File 'lib/node_query/compiler/identifier.rb', line 23 def actual_value(node) if @adapter.is_node?(node) @adapter.get_source(node) elsif node.is_a?(::Array) node.map { |n| actual_value(n) } else node.to_s end end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/node_query/compiler/identifier.rb', line 39 def to_s @value end |
#valid_operators ⇒ Array
Get valid operators.
35 36 37 |
# File 'lib/node_query/compiler/identifier.rb', line 35 def valid_operators STRING_VALID_OPERATORS end |