Class: Cel::MapType
Instance Attribute Summary collapse
-
#element_type ⇒ Object
Returns the value of attribute element_type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cast(value) ⇒ Object
- #convert(primitive_value) ⇒ Object
- #get(attrib) ⇒ Object
-
#initialize(type_map) ⇒ MapType
constructor
A new instance of MapType.
Methods inherited from Type
Methods included from CelMethods
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_type ⇒ Object
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 |