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