Class: Janeway::AST::IndexSelector

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

Overview

An index selector, e.g. 3, selects an indexed child of an array @example: $.store.book.title

Instance Attribute Summary

Attributes inherited from Selector

#next

Attributes inherited from Expression

#next, #value

Instance Method Summary collapse

Methods inherited from Selector

#==

Methods inherited from Expression

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

Constructor Details

#initialize(index) ⇒ IndexSelector

Returns a new instance of IndexSelector.

Raises:



11
12
13
14
15
16
17
# File 'lib/janeway/ast/index_selector.rb', line 11

def initialize(index)
  raise Error, "Invalid value for index selector: #{index.inspect}" unless index.is_a?(Integer)
  raise Error, "Index selector value too small: #{index.inspect}" if index < INTEGER_MIN
  raise Error, "Index selector value too large: #{index.inspect}" if index > INTEGER_MAX

  super
end

Instance Method Details

#to_s(brackets: true, **_ignored) ⇒ Object

Parameters:

  • brackets (Boolean) (defaults to: true)

    include brackets around selector



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

def to_s(brackets: true, **_ignored)
  brackets ? "[#{@value}]#{@next}" : "#{@value}#{@next}"
end