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
32 def initialize(nanoseconds)
33   @nsecs = nanoseconds
34 end

Public Instance Methods

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

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

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

@return [Float] the number of seconds

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

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

   # File lib/puppet/pops/time/timespan.rb
59 def to_int
60   @nsecs / NSECS_PER_SEC
61 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
73 def to_r
74   Rational(@nsecs, NSECS_PER_SEC)
75 end