Class: Synvert::Core::NodeQuery::Compiler::Identifier

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/synvert/core/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

Instance Method Summary collapse

Methods included from Comparable

#expected_value, #match?, #valid_operator?

Constructor Details

#initialize(value:) ⇒ Identifier

Initialize an Identifier.



11
12
13
# File 'lib/synvert/core/node_query/compiler/identifier.rb', line 11

def initialize(value:)
  @value = value
end

Instance Method Details

#actual_value(node) ⇒ String|Array

Get the actual value.

If the node is a Parser::AST::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.



22
23
24
25
26
27
28
29
30
# File 'lib/synvert/core/node_query/compiler/identifier.rb', line 22

def actual_value(node)
  if node.is_a?(::Parser::AST::Node)
    node.to_source
  elsif node.is_a?(::Array)
    node.map { |n| actual_value(n) }
  else
    node.to_s
  end
end

#to_sObject



37
38
39
# File 'lib/synvert/core/node_query/compiler/identifier.rb', line 37

def to_s
  @value
end

#valid_operatorsObject

Get valid operators.



33
34
35
# File 'lib/synvert/core/node_query/compiler/identifier.rb', line 33

def valid_operators
  SIMPLE_VALID_OPERATORS
end