Class: Liquid2::Path
- Inherits:
-
Expression
- Object
- Expression
- Liquid2::Path
- Defined in:
- lib/liquid2/expressions/path.rb
Overview
A path to some variable data. If the path has just one segment, it is often just called a "variable".
Constant Summary collapse
- RE_PROPERTY =
/\A[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*\Z/
Instance Attribute Summary collapse
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Attributes inherited from Expression
Instance Method Summary collapse
- #children ⇒ Object
- #evaluate(context) ⇒ Object
-
#initialize(token, segments) ⇒ Path
constructor
A new instance of Path.
- #to_s ⇒ Object
Methods inherited from Expression
Constructor Details
#initialize(token, segments) ⇒ Path
Returns a new instance of Path.
14 15 16 17 18 |
# File 'lib/liquid2/expressions/path.rb', line 14 def initialize(token, segments) super(token) @segments = segments @head = @segments.shift end |
Instance Attribute Details
#head ⇒ Object (readonly)
Returns the value of attribute head.
9 10 11 |
# File 'lib/liquid2/expressions/path.rb', line 9 def head @head end |
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
9 10 11 |
# File 'lib/liquid2/expressions/path.rb', line 9 def segments @segments end |
Instance Method Details
#children ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/liquid2/expressions/path.rb', line 28 def children if @head.is_a?(Path) [@head, *@segments.filter { |segment| segment.is_a?(Path) }] else @segments.filter { |segment| segment.is_a?(Path) } end end |
#evaluate(context) ⇒ Object
20 21 22 |
# File 'lib/liquid2/expressions/path.rb', line 20 def evaluate(context) context.fetch(@head, @segments, node: self) end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/liquid2/expressions/path.rb', line 24 def to_s segment_to_s(@head, head: true) + @segments.map { |segment| segment_to_s(segment) }.join end |