Class: Synvert::Core::NodeQuery::Compiler::String

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/synvert/core/node_query/compiler/string.rb

Overview

String represents a ruby string value.

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:) ⇒ String

Initialize a String.

Parameters:

  • value (String)

    the string value



10
11
12
# File 'lib/synvert/core/node_query/compiler/string.rb', line 10

def initialize(value:)
  @value = value
end

Instance Method Details

#actual_value(node) ⇒ String

Get the actual value of a node.

Parameters:

Returns:

  • (String)

    if node is a Parser::AST::Node, return the node source code, otherwise, return the string value.



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

def actual_value(node)
  if node.is_a?(::Parser::AST::Node)
    node.to_source
  else
    node.to_s
  end
end

#to_sObject



30
31
32
# File 'lib/synvert/core/node_query/compiler/string.rb', line 30

def to_s
  "\"#{@value}\""
end

#valid_operatorsObject

Get valid operators.



15
16
17
# File 'lib/synvert/core/node_query/compiler/string.rb', line 15

def valid_operators
  SIMPLE_VALID_OPERATORS
end