Class: Janeway::AST::ChildSegment
- Inherits:
-
Expression
- Object
- Expression
- Janeway::AST::ChildSegment
- Extended by:
- Forwardable
- Defined in:
- lib/janeway/ast/child_segment.rb
Overview
Represent a union of 2 or more selectors.
A set of selectors within brackets, as a comma-separated list. www.rfc-editor.org/rfc/rfc9535.html#child-segment
Instance Attribute Summary collapse
-
#next ⇒ Object
Subsequent expression that modifies the result of this selector list.
Attributes inherited from Expression
Instance Method Summary collapse
-
#<<(selector) ⇒ Object
Add a selector to the list.
-
#initialize ⇒ ChildSegment
constructor
A new instance of ChildSegment.
- #to_s(with_child: true) ⇒ Object
- #tree(level) ⇒ Array
Methods inherited from Expression
#indented, #literal?, #singular_query?, #type
Constructor Details
#initialize ⇒ ChildSegment
Returns a new instance of ChildSegment.
23 24 25 |
# File 'lib/janeway/ast/child_segment.rb', line 23 def initialize super([]) # @value holds the expressions in the selector end |
Instance Attribute Details
#next ⇒ Object
Subsequent expression that modifies the result of this selector list.
21 22 23 |
# File 'lib/janeway/ast/child_segment.rb', line 21 def next @next end |
Instance Method Details
#<<(selector) ⇒ Object
Add a selector to the list
28 29 30 31 32 |
# File 'lib/janeway/ast/child_segment.rb', line 28 def <<(selector) raise ArgumentError, "expect Selector, got #{selector.inspect}" unless selector.is_a?(Selector) @value << selector end |
#to_s(with_child: true) ⇒ Object
34 35 36 37 |
# File 'lib/janeway/ast/child_segment.rb', line 34 def to_s(with_child: true) str = @value.map { |selector| selector.to_s(brackets: false, dot_prefix: false) }.join(', ') with_child ? "[#{str}]#{@next}" : "[#{str}]" end |
#tree(level) ⇒ Array
41 42 43 44 |
# File 'lib/janeway/ast/child_segment.rb', line 41 def tree(level) msg = format('[%s]', @value.map(&:to_s).join(', ')) [indented(level, msg), @next&.tree(level + 1)] end |