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, #type

Constructor Details

#initialize(type_map) ⇒ MapType

Returns a new instance of MapType.



74
75
76
77
78
# File 'lib/cel/ast/types.rb', line 74

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.



72
73
74
# File 'lib/cel/ast/types.rb', line 72

def element_type
  @element_type
end

Instance Method Details

#==(other) ⇒ Object



85
86
87
# File 'lib/cel/ast/types.rb', line 85

def ==(other)
  other == :map || super
end

#cast(value) ⇒ Object



89
90
91
# File 'lib/cel/ast/types.rb', line 89

def cast(value)
  Map.new(value)
end

#get(attrib) ⇒ Object



80
81
82
83
# File 'lib/cel/ast/types.rb', line 80

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