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, #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

#getHoursObject

Cel Functions



485
486
487
# File 'lib/cel/ast/elements.rb', line 485

def getHours
  (getMinutes / 60).to_i
end

#getMillisecondsObject



497
498
499
# File 'lib/cel/ast/elements.rb', line 497

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

#getMinutesObject



489
490
491
# File 'lib/cel/ast/elements.rb', line 489

def getMinutes
  (getSeconds / 60).to_i
end

#getSecondsObject



493
494
495
# File 'lib/cel/ast/elements.rb', line 493

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