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

Attributes inherited from Expression

#next, #value

Instance Method Summary collapse

Methods inherited from Expression

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

Constructor Details

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

Instance Method Details

#selectorAST::Selector

Returns:



25
26
27
# File 'lib/janeway/ast/descendant_segment.rb', line 25

def selector
  value
end

#to_sObject



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

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

#tree(level) ⇒ Array

Parameters:

  • level (Integer)

Returns:

  • (Array)


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

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