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

#==, #cast, #to_str, #type

Constructor Details

#initialize(type_map) ⇒ MapType

Returns a new instance of MapType.



60
61
62
63
64
# File 'lib/cel/ast/types.rb', line 60

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

Instance Attribute Details

#element_typeObject

Returns the value of attribute element_type.



58
59
60
# File 'lib/cel/ast/types.rb', line 58

def element_type
  @element_type
end

Instance Method Details

#get(attrib) ⇒ Object



66
67
68
69
# File 'lib/cel/ast/types.rb', line 66

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