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.



76
77
78
79
80
# File 'lib/cel/ast/types.rb', line 76

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.



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

def element_type
  @element_type
end

Instance Method Details

#==(other) ⇒ Object



87
88
89
# File 'lib/cel/ast/types.rb', line 87

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

#cast(value) ⇒ Object



91
92
93
# File 'lib/cel/ast/types.rb', line 91

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

#get(attrib) ⇒ Object



82
83
84
85
# File 'lib/cel/ast/types.rb', line 82

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