Class: Cel::Literal
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Cel::Literal
- Defined in:
- lib/cel/ast/elements.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(type, value) ⇒ Literal
constructor
A new instance of Literal.
Constructor Details
#initialize(type, value) ⇒ Literal
Returns a new instance of Literal.
73 74 75 76 77 78 |
# File 'lib/cel/ast/elements.rb', line 73 def initialize(type, value) @type = type.is_a?(Type) ? type : TYPES[type] @value = value super(value) check end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
71 72 73 |
# File 'lib/cel/ast/elements.rb', line 71 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
71 72 73 |
# File 'lib/cel/ast/elements.rb', line 71 def value @value end |
Class Method Details
.to_cel_type(val) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/cel/ast/elements.rb', line 84 def self.to_cel_type(val) case val when Literal, Identifier val # TODO: should support byte streams? 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.new(val) when nil Null.new else raise BindingError, "can't convert #{val} to CEL type" end end |
Instance Method Details
#==(other) ⇒ Object
80 81 82 |
# File 'lib/cel/ast/elements.rb', line 80 def ==(other) @value == other || super end |