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. https://www.rfc-editor.org/rfc/rfc9535.html#child-segment
Instance Attribute Summary
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
#chain_of?, #indented, #literal?, #singular_query?, #type, type_name
Constructor Details
#initialize ⇒ ChildSegment
Returns a new instance of ChildSegment.
21 22 23 |
# File 'lib/janeway/ast/child_segment.rb', line 21 def initialize super([]) # @value holds the expressions in the selector end |
Instance Method Details
#<<(selector) ⇒ Object
Add a selector to the list
26 27 28 29 30 |
# File 'lib/janeway/ast/child_segment.rb', line 26 def <<(selector) raise ArgumentError, "expect Selector, got #{selector.inspect}" unless selector.is_a?(Selector) @value << selector end |
#to_s(with_child: true) ⇒ Object
32 33 34 35 |
# File 'lib/janeway/ast/child_segment.rb', line 32 def to_s(with_child: true, **) str = @value.map { |selector| selector.to_s(brackets: false, dot_prefix: false, bracketed: true) }.join(', ') with_child ? "[#{str}]#{@next}" : "[#{str}]" end |
#tree(level) ⇒ Array
39 40 41 42 |
# File 'lib/janeway/ast/child_segment.rb', line 39 def tree(level) msg = format('[%s]', @value.map(&:to_s).join(', ')) [indented(level, msg), @next&.tree(level + 1)] end |