Class: Janeway::AST::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/janeway/ast/expression.rb

Overview

Base class for jsonpath expressions.

Every AST node is a subclass of this. This includes selectors, root and child identifiers, descendant segments, and the nodes that occur within a filter selector such as the current node identifier, operators and literals.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(val = nil) ⇒ Expression

Returns a new instance of Expression.



23
24
25
26
27
# File 'lib/janeway/ast/expression.rb', line 23

def initialize(val = nil)
  # don't set the instance variable if unused, because it makes the
  # "#inspect" output cleaner in rspec test failures
  @value = val unless val.nil? # literal false must be stored though!
end

Instance Attribute Details

#nextObject (readonly)

Next expression in the AST, if any



21
22
23
# File 'lib/janeway/ast/expression.rb', line 21

def next
  @next
end

#valueObject

Value provided by subclass constructor.



18
19
20
# File 'lib/janeway/ast/expression.rb', line 18

def value
  @value
end

Instance Method Details

#indented(level, msg) ⇒ String

Return the given message, indented

Parameters:

  • level (Integer)
  • msg (String)

Returns:

  • (String)


40
41
42
# File 'lib/janeway/ast/expression.rb', line 40

def indented(level, msg)
  format('%s%s', INDENT * level, msg)
end

#literal?Boolean

Return true if this is a literal expression

Returns:



52
53
54
# File 'lib/janeway/ast/expression.rb', line 52

def literal?
  false
end

#singular_query?Boolean

True if this is the root of a singular-query.



60
61
62
# File 'lib/janeway/ast/expression.rb', line 60

def singular_query?
  false
end

#tree(level) ⇒ Array

Parameters:

  • level (Integer)

Returns:

  • (Array)


46
47
48
# File 'lib/janeway/ast/expression.rb', line 46

def tree(level)
  [indented(level, to_s)]
end

#typeString

Returns:

  • (String)


30
31
32
33
# File 'lib/janeway/ast/expression.rb', line 30

def type
  name = self.class.to_s.split('::').last # eg. Janeway::AST::FunctionCall => "FunctionCall"
  Helpers.camelcase_to_underscore(name) # eg. "FunctionCall" => "function_call"
end