class Puppet::Pops::Time::Timespan::Format::FragmentSegment

Class that assumes that leading zeroes are significant and that trailing zeroes are not and left justifies when formatting. Applicable after a decimal point, and hence to the %L and %N formats.

Public Instance Methods

append_value(bld, n) click to toggle source
    # File lib/puppet/pops/time/timespan.rb
493 def append_value(bld, n)
494   # Strip trailing zeroes when default format is used
495   n = n.to_s.sub(/\A([0-9]+?)0*\z/, '\1').to_i unless use_total? || @padchar == '0'
496   super(bld, n)
497 end
create_format() click to toggle source
    # File lib/puppet/pops/time/timespan.rb
485 def create_format
486   if @padchar.nil?
487     '%d'
488   else
489     "%-#{@width || @default_width}d"
490   end
491 end
nanoseconds(group) click to toggle source
    # File lib/puppet/pops/time/timespan.rb
476 def nanoseconds(group)
477   # Using %L or %N to parse a string only makes sense when they are considered to be fractions. Using them
478   # as a total quantity would introduce ambiguities.
479   raise ArgumentError, _('Format specifiers %L and %N denotes fractions and must be used together with a specifier of higher magnitude') if use_total?
480   n = group.to_i
481   p = 9 - group.length
482   p <= 0 ? n : n * 10 ** p
483 end