Class: Cel::ListType

Inherits:
Type
  • Object
show all
Defined in:
lib/cel/ast/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#to_str, #to_sym, #type

Methods included from CelMethods

included

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_typeObject

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