class Puppet::Pops::Time::TimeData

TimeData is a Numeric that stores its value internally as nano-seconds but will be considered to be seconds and fractions of seconds when used in arithmetic or comparison with other Numeric types.

Attributes

nsecs[R]

Public Class Methods

new(nanoseconds) click to toggle source
   # File lib/puppet/pops/time/timespan.rb
31 def initialize(nanoseconds)
32   @nsecs = nanoseconds
33 end

Public Instance Methods

<=>(o) click to toggle source
   # File lib/puppet/pops/time/timespan.rb
35 def <=>(o)
36   case o
37   when self.class
38     @nsecs <=> o.nsecs
39   when Integer
40     to_int <=> o
41   when Float
42     to_f <=> o
43   else
44     nil
45   end
46 end
label(o) click to toggle source
   # File lib/puppet/pops/time/timespan.rb
48 def label(o)
49   Utils.name_to_segments(o.class.name).last
50 end
to_c() click to toggle source

@return [Complex] short for `#to_f.to_c`

   # File lib/puppet/pops/time/timespan.rb
67 def to_c
68   to_f.to_c
69 end
to_f() click to toggle source

@return [Float] the number of seconds

   # File lib/puppet/pops/time/timespan.rb
53 def to_f
54   @nsecs.fdiv(NSECS_PER_SEC)
55 end
to_i() click to toggle source
   # File lib/puppet/pops/time/timespan.rb
62 def to_i
63   to_int
64 end
to_int() click to toggle source

@return [Integer] the number of seconds with fraction part truncated

   # File lib/puppet/pops/time/timespan.rb
58 def to_int
59   @nsecs / NSECS_PER_SEC
60 end
to_r() click to toggle source

@return [Rational] initial numerator is nano-seconds and denominator is nano-seconds per second

   # File lib/puppet/pops/time/timespan.rb
72 def to_r
73   Rational(@nsecs, NSECS_PER_SEC)
74 end