Class: Janeway::AST::DescendantSegment

Inherits:
Selector show all
Defined in:
lib/janeway/ast/descendant_segment.rb

Overview

An array slice start:end:step selects a series of elements from an array, giving a start position, an end position, and an optional step value that moves the position from the start to the end.

Examples:

$..j      Values of keys equal to 'j'
$..[0]    First entry of any array
$..[*]    All values
$..*      All values
$..[*, *] All values, twice non-deterministic order
$..[0, 1] Multiple segments

Instance Attribute Summary collapse

Attributes inherited from Expression

#value

Instance Method Summary collapse

Methods inherited from Selector

#==

Methods inherited from Expression

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

Constructor Details

This class inherits a constructor from Janeway::AST::Expression

Instance Attribute Details

#nextObject

Subsequent expression that modifies the result of this selector list.



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

def next
  @next
end

Instance Method Details

#selectorAST::Selector

Returns:



28
29
30
# File 'lib/janeway/ast/descendant_segment.rb', line 28

def selector
  value
end

#to_sObject



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

def to_s
  "..#{@next&.to_s(dot_prefix: false)}"
end

#tree(level) ⇒ Array

Parameters:

  • level (Integer)

Returns:

  • (Array)


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

def tree(level)
  [indented(level, "..#{@value}"), @next&.tree(level + 1)]
end