Class: Janeway::AST::RootNode
- Inherits:
-
Expression
- Object
- Expression
- Janeway::AST::RootNode
- Defined in:
- lib/janeway/ast/root_node.rb
Overview
Every JSONPath query (except those inside filter expressions; see Section 2.3.5) MUST begin with the root identifier $.
The root identifier $ represents the root node of the query argument and produces a nodelist consisting of that root node.
The root identifier may also be used in the filter selectors.
@example:
$(? $.key1 == $.key2 )
Instance Attribute Summary
Attributes inherited from Expression
Instance Method Summary collapse
-
#singular_query? ⇒ Boolean
True if this is the root of a singular-query.
- #to_s ⇒ Object
- #tree(level = 0) ⇒ Array
Methods inherited from Expression
#indented, #initialize, #literal?, #type
Constructor Details
This class inherits a constructor from Janeway::AST::Expression
Instance Method Details
#singular_query? ⇒ Boolean
True if this is the root of a singular-query.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/janeway/ast/root_node.rb', line 25 def singular_query? return true unless @value # there are no following selectors selector_types = [] selector = @value loop do selector_types << selector.class selector = selector.next break unless selector end allowed = [AST::IndexSelector, AST::NameSelector] selector_types.uniq.all? { allowed.include?(_1) } end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/janeway/ast/root_node.rb', line 17 def to_s "$#{@value}" end |
#tree(level = 0) ⇒ Array
41 42 43 |
# File 'lib/janeway/ast/root_node.rb', line 41 def tree(level = 0) [indented(level, '$'), @value.tree(level + 1)] end |