Class: Cel::List
- Defined in:
- lib/cel/ast/elements/list.rb,
lib/cel/extensions/string.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
Attributes inherited from Literal
Instance Method Summary collapse
- #by_max_depth ⇒ Object
-
#initialize(value, depth: 1) ⇒ List
constructor
A new instance of List.
- #to_ary ⇒ Object
- #to_ruby_type ⇒ Object
- #to_s ⇒ Object
Methods inherited from Literal
Methods included from CelMethods
Constructor Details
#initialize(value, depth: 1) ⇒ List
Returns a new instance of List.
7 8 9 10 11 12 13 |
# File 'lib/cel/ast/elements/list.rb', line 7 def initialize(value, depth: 1) value = value.map do |v| Literal.to_cel_type(v) end super(TYPES[:list], value) @depth = depth end |
Instance Attribute Details
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
5 6 7 |
# File 'lib/cel/ast/elements/list.rb', line 5 def depth @depth end |
Instance Method Details
#by_max_depth ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/cel/ast/elements/list.rb', line 44 def by_max_depth max = @value.max { |a1, a2| calc_depth(a1, 0) <=> calc_depth(a2, 0) } # return the last value if all options have the same depth return @value.last if (max == @value.first) && (calc_depth(max, 0) == calc_depth(@value.last, 0)) max end |
#to_ary ⇒ Object
28 29 30 |
# File 'lib/cel/ast/elements/list.rb', line 28 def to_ary [self] end |
#to_ruby_type ⇒ Object
32 33 34 |
# File 'lib/cel/ast/elements/list.rb', line 32 def to_ruby_type value.map(&:to_ruby_type) end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/cel/ast/elements/list.rb', line 53 def to_s "[#{@value.map(&:to_s).join(", ")}]" end |