Class: Janeway::AST::WildcardSelector

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

Overview

A wildcard selector selects the nodes of all children of an object or array. The order in which the children of an object appear in the resultant nodelist is not stipulated, since JSON objects are unordered. Children of an array appear in array order in the resultant nodelist.

Note that the children of an object are its member values, not its member names/keys.

The wildcard selector selects nothing from a primitive JSON value (ie. a number, a string, true, false, or null).

It has only one possible value: ‘*’ @example: $.store.book

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?, #type

Constructor Details

#initializeWildcardSelector

Returns a new instance of WildcardSelector.



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

def initialize
  super
  @next = nil
end

Instance Method Details

#to_s(brackets: false, dot_prefix: true) ⇒ String

Returns:

  • (String)


26
27
28
29
30
31
32
33
34
# File 'lib/janeway/ast/wildcard_selector.rb', line 26

def to_s(brackets: false, dot_prefix: true)
  if brackets
    "[*]#{@next&.to_s(brackets: true)}"
  elsif dot_prefix
    ".*#{@next}"
  else
    "*#{@next}"
  end
end

#tree(level) ⇒ Array

Parameters:

  • level (Integer)

Returns:

  • (Array)


38
39
40
# File 'lib/janeway/ast/wildcard_selector.rb', line 38

def tree(level)
  [indented(level, '*'), @next.tree(level + 1)]
end