Class: Cel::Duration
- Defined in:
- lib/cel/ast/elements.rb
Instance Attribute Summary
Attributes inherited from Literal
Instance Method Summary collapse
-
#getHours ⇒ Object
Cel Functions.
- #getMilliseconds ⇒ Object
- #getMinutes ⇒ Object
- #getSeconds ⇒ Object
-
#initialize(value) ⇒ Duration
constructor
A new instance of Duration.
Methods inherited from Literal
#==, to_cel_type, #to_ruby_type
Constructor Details
#initialize(value) ⇒ Duration
Returns a new instance of Duration.
444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/cel/ast/elements.rb', line 444 def initialize(value) value = case value when String init_from_string(value) when Hash seconds, nanos = value.values_at(:seconds, :nanos) seconds ||= 0 nanos ||= 0 seconds + (nanos / 1_000_000_000.0) else value end super(:duration, value) end |
Instance Method Details
#getHours ⇒ Object
Cel Functions
477 478 479 |
# File 'lib/cel/ast/elements.rb', line 477 def getHours (getMinutes / 60).to_i end |
#getMilliseconds ⇒ Object
489 490 491 |
# File 'lib/cel/ast/elements.rb', line 489 def getMilliseconds (@value.divmod(1).last * 1000).round end |
#getMinutes ⇒ Object
481 482 483 |
# File 'lib/cel/ast/elements.rb', line 481 def getMinutes (getSeconds / 60).to_i end |
#getSeconds ⇒ Object
485 486 487 |
# File 'lib/cel/ast/elements.rb', line 485 def getSeconds @value.divmod(1).first end |