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.
452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/cel/ast/elements.rb', line 452 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
485 486 487 |
# File 'lib/cel/ast/elements.rb', line 485 def getHours (getMinutes / 60).to_i end |
#getMilliseconds ⇒ Object
497 498 499 |
# File 'lib/cel/ast/elements.rb', line 497 def getMilliseconds (@value.divmod(1).last * 1000).round end |
#getMinutes ⇒ Object
489 490 491 |
# File 'lib/cel/ast/elements.rb', line 489 def getMinutes (getSeconds / 60).to_i end |
#getSeconds ⇒ Object
493 494 495 |
# File 'lib/cel/ast/elements.rb', line 493 def getSeconds @value.divmod(1).first end |