Class: Puppet::Pops::Time::Timespan::Format::NanoSecondSegment

Inherits:
FragmentSegment show all
Defined in:
lib/puppet/pops/time/timespan.rb

Instance Method Summary collapse

Methods inherited from FragmentSegment

#append_value, #create_format, #nanoseconds

Methods inherited from ValueSegment

#append_regexp, #append_value, #create_format, #nanoseconds, #set_use_total, #use_total?

Methods inherited from Segment

#append_regexp

Constructor Details

#initialize(padchar, width) ⇒ NanoSecondSegment

Returns a new instance of NanoSecondSegment.



518
519
520
# File 'lib/puppet/pops/time/timespan.rb', line 518

def initialize(padchar, width)
  super(padchar, width, 9)
end

Instance Method Details

#append_to(bld, ts) ⇒ Object



531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/puppet/pops/time/timespan.rb', line 531

def append_to(bld, ts)
  ns = ts.total_nanoseconds
  width = @width || @default_width
  if width < 9
    # Truncate digits to the right, i.e. let %6N reflect microseconds
    ns /= 10**(9 - width)
    ns %= 10**width unless use_total?
  else
    ns %= NSECS_PER_SEC unless use_total?
  end
  append_value(bld, ns)
end

#multiplierObject



522
523
524
525
526
527
528
529
# File 'lib/puppet/pops/time/timespan.rb', line 522

def multiplier
  width = @width || @default_width
  if width < 9
    10**(9 - width)
  else
    1
  end
end