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
Constructor Details
#initialize(value) ⇒ Duration
Returns a new instance of Duration.
432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/cel/ast/elements.rb', line 432 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
465 466 467 |
# File 'lib/cel/ast/elements.rb', line 465 def getHours (getMinutes / 60).to_i end |
#getMilliseconds ⇒ Object
477 478 479 |
# File 'lib/cel/ast/elements.rb', line 477 def getMilliseconds (@value.divmod(1).last * 1000).round end |
#getMinutes ⇒ Object
469 470 471 |
# File 'lib/cel/ast/elements.rb', line 469 def getMinutes (getSeconds / 60).to_i end |
#getSeconds ⇒ Object
473 474 475 |
# File 'lib/cel/ast/elements.rb', line 473 def getSeconds @value.divmod(1).first end |