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

#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) ⇒ Object

** ignores keyword arguments that don’t apply to this selector



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

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