Class: Cel::ListType
Instance Attribute Summary collapse
-
#element_type ⇒ Object
Returns the value of attribute element_type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cast(value) ⇒ Object
- #convert(primitive_value) ⇒ Object
- #get(idx) ⇒ Object
-
#initialize(type_list) ⇒ ListType
constructor
A new instance of ListType.
Methods inherited from Type
Methods included from CelMethods
Constructor Details
#initialize(type_list) ⇒ ListType
Returns a new instance of ListType.
191 192 193 194 195 |
# File 'lib/cel/ast/types.rb', line 191 def initialize(type_list) super(:list) @type_list = type_list @element_type = @type_list.empty? ? TYPES[:any] : @type_list.sample.type end |
Instance Attribute Details
#element_type ⇒ Object
Returns the value of attribute element_type.
189 190 191 |
# File 'lib/cel/ast/types.rb', line 189 def element_type @element_type end |
Instance Method Details
#==(other) ⇒ Object
203 204 205 |
# File 'lib/cel/ast/types.rb', line 203 def ==(other) (other.is_a?(self.class) && other.element_type == @element_type) || super end |
#cast(value) ⇒ Object
207 208 209 |
# File 'lib/cel/ast/types.rb', line 207 def cast(value) value.is_a?(List) ? value : convert(value) end |
#convert(primitive_value) ⇒ Object
211 212 213 |
# File 'lib/cel/ast/types.rb', line 211 def convert(primitive_value) List.new(primitive_value) end |
#get(idx) ⇒ Object
197 198 199 200 201 |
# File 'lib/cel/ast/types.rb', line 197 def get(idx) return @element_type if @type_list.empty? @type_list[idx] end |