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.


514
515
516
# File 'lib/puppet/pops/time/timespan.rb', line 514

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

Instance Method Details

#append_to(bld, ts) ⇒ Object


527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/puppet/pops/time/timespan.rb', line 527

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


518
519
520
521
522
523
524
525
# File 'lib/puppet/pops/time/timespan.rb', line 518

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