Class: Janeway::AST::ChildSegment

Inherits:
Expression show all
Extended by:
Forwardable
Defined in:
lib/janeway/ast/child_segment.rb

Overview

Represent a union of 2 or more selectors.

Instance Attribute Summary collapse

Attributes inherited from Expression

#value

Instance Method Summary collapse

Methods inherited from Expression

#indented, #literal?, #singular_query?, #type

Constructor Details

#initializeChildSegment



22
23
24
# File 'lib/janeway/ast/child_segment.rb', line 22

def initialize
  super([]) # @value holds the expressions in the selector
end

Instance Attribute Details

#nextObject

Subsequent expression that modifies the result of this selector list.



20
21
22
# File 'lib/janeway/ast/child_segment.rb', line 20

def next
  @next
end

Instance Method Details

#<<(selector) ⇒ Object

Add a selector to the list

Raises:

  • (ArgumentError)


27
28
29
30
31
# File 'lib/janeway/ast/child_segment.rb', line 27

def <<(selector)
  raise ArgumentError, "expect Selector, got #{selector.inspect}" unless selector.is_a?(Selector)

  @value << selector
end

#to_s(with_child: true) ⇒ Object



33
34
35
36
# File 'lib/janeway/ast/child_segment.rb', line 33

def to_s(with_child: true)
  str = @value.map { |selector| selector.to_s(brackets: false, dot_prefix: false) }.join(', ')
  with_child ? "[#{str}]#{@next}" : "[#{str}]"
end

#tree(level) ⇒ Array



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

def tree(level)
  msg = format('[%s]', @value.map(&:to_s).join(', '))
  [indented(level, msg), @next&.tree(level + 1)]
end