Class: Cel::MapType

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_map) ⇒ MapType



222
223
224
225
226
# File 'lib/cel/ast/types.rb', line 222

def initialize(type_map)
  super(:map)
  @type_map = type_map
  @element_type = @type_map.empty? ? TYPES[:any] : @type_map.sample.first.type
end

Instance Attribute Details

#element_typeObject

Returns the value of attribute element_type.



217
218
219
# File 'lib/cel/ast/types.rb', line 217

def element_type
  @element_type
end

Instance Method Details

#==(other) ⇒ Object



233
234
235
236
# File 'lib/cel/ast/types.rb', line 233

def ==(other)
  (other.is_a?(self.class) && other.element_type == @element_type && other.type_map == @type_map) || super
  other == :map || super
end

#cast(value) ⇒ Object



238
239
240
# File 'lib/cel/ast/types.rb', line 238

def cast(value)
  value.is_a?(Map) ? value : convert(value)
end

#convert(primitive_value) ⇒ Object



242
243
244
# File 'lib/cel/ast/types.rb', line 242

def convert(primitive_value)
  Map.new(primitive_value)
end

#get(attrib) ⇒ Object



228
229
230
231
# File 'lib/cel/ast/types.rb', line 228

def get(attrib)
  _, value = @type_map.find { |k, _| k == attrib }
  value
end