Class: Cel::Literal
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Cel::Literal
- Includes:
- CelMethods
- Defined in:
- lib/cel/ast/elements/literal.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
(also: #to_ruby_type)
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type, value) ⇒ Literal
constructor
A new instance of Literal.
Methods included from CelMethods
Constructor Details
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/cel/ast/elements/literal.rb', line 7 def type @type end |
#value ⇒ Object (readonly) Also known as: to_ruby_type
Returns the value of attribute value.
7 8 9 |
# File 'lib/cel/ast/elements/literal.rb', line 7 def value @value end |
Class Method Details
.to_cel_type(val) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cel/ast/elements/literal.rb', line 10 def to_cel_type(val) if val.is_a?(Protobuf.base_class) || val.is_a?(Struct) # no-protobuf mode val = Protobuf.try_convert_from_wrapper(val) return val if val.is_a?(Protobuf.base_class) # still end case val when Literal, Identifier, Invoke, Operation, Condition, Group, # already cel Protobuf.enum_class # already a usable class a la protobuf val when Protobuf.map_class Map.new(val.to_h) when ::String String.new(val) when ::Symbol Identifier.new(val) when ::Integer Number.new(:int, val) when ::Float, ::BigDecimal Number.new(:double, val) when ::Hash Map.new(val) when ::Array List.new(val) when true, false Bool.cast(val) when nil Null::INSTANCE when Time Timestamp.new(val) else raise BindingError, "can't convert #{val} to CEL type" end end |