Class: Cel::Duration

Inherits:
Literal
  • Object
show all
Defined in:
lib/cel/ast/elements.rb

Instance Attribute Summary

Attributes inherited from Literal

#type, #value

Instance Method Summary collapse

Methods inherited from Literal

#==, to_cel_type

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

#getHoursObject

Cel Functions



465
466
467
# File 'lib/cel/ast/elements.rb', line 465

def getHours
  (getMinutes / 60).to_i
end

#getMillisecondsObject



477
478
479
# File 'lib/cel/ast/elements.rb', line 477

def getMilliseconds
  (@value.divmod(1).last * 1000).round
end

#getMinutesObject



469
470
471
# File 'lib/cel/ast/elements.rb', line 469

def getMinutes
  (getSeconds / 60).to_i
end

#getSecondsObject



473
474
475
# File 'lib/cel/ast/elements.rb', line 473

def getSeconds
  @value.divmod(1).first
end