Class: Cel::Type
- Inherits:
-
Object
- Object
- Cel::Type
- Defined in:
- lib/cel/ast/types.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cast(value) ⇒ Object
-
#initialize(type) ⇒ Type
constructor
A new instance of Type.
- #to_str ⇒ Object (also: #to_s)
- #type ⇒ Object
Constructor Details
#initialize(type) ⇒ Type
Returns a new instance of Type.
5 6 7 |
# File 'lib/cel/ast/types.rb', line 5 def initialize(type) @type = type end |
Instance Method Details
#==(other) ⇒ Object
9 10 11 |
# File 'lib/cel/ast/types.rb', line 9 def ==(other) other == @type || super end |
#cast(value) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cel/ast/types.rb', line 23 def cast(value) value = value.value if value.is_a?(Literal) case @type when :int Number.new(:int, Integer(value)) when :uint Number.new(:uint, Integer(value).abs) when :double Number.new(:double, Float(value)) when :string String.new(String(value)) when :bytes Bytes.new(value.bytes) when :bool Bool.new(value) when :timestamp Timestamp.new(value) when :duration Duration.new(value) when :any value else raise Error, "unsupported cast operation to #{@type}" end end |
#to_str ⇒ Object Also known as: to_s
13 14 15 |
# File 'lib/cel/ast/types.rb', line 13 def to_str @type.to_s end |
#type ⇒ Object
19 20 21 |
# File 'lib/cel/ast/types.rb', line 19 def type TYPES[:type] end |