Class: Puppet::Pops::Time::Timespan::Format::FragmentSegment
- Inherits:
-
ValueSegment
- Object
- Segment
- ValueSegment
- Puppet::Pops::Time::Timespan::Format::FragmentSegment
- Defined in:
- lib/puppet/pops/time/timespan.rb
Overview
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.
Direct Known Subclasses
Instance Method Summary collapse
Methods inherited from ValueSegment
#append_regexp, #initialize, #multiplier, #set_use_total, #use_total?
Methods inherited from Segment
#append_regexp, #append_to, #multiplier
Constructor Details
This class inherits a constructor from Puppet::Pops::Time::Timespan::Format::ValueSegment
Instance Method Details
#append_value(bld, n) ⇒ Object
496 497 498 499 500 |
# File 'lib/puppet/pops/time/timespan.rb', line 496 def append_value(bld, n) # Strip trailing zeroes when default format is used n = n.to_s.sub(/\A([0-9]+?)0*\z/, '\1').to_i unless use_total? || @padchar == '0' super(bld, n) end |
#create_format ⇒ Object
488 489 490 491 492 493 494 |
# File 'lib/puppet/pops/time/timespan.rb', line 488 def create_format if @padchar.nil? '%d' else "%-#{@width || @default_width}d" end end |
#nanoseconds(group) ⇒ Object
478 479 480 481 482 483 484 485 486 |
# File 'lib/puppet/pops/time/timespan.rb', line 478 def nanoseconds(group) # Using %L or %N to parse a string only makes sense when they are considered to be fractions. Using them # as a total quantity would introduce ambiguities. raise ArgumentError, _('Format specifiers %L and %N denotes fractions and must be used together with a specifier of higher magnitude') if use_total? n = group.to_i p = 9 - group.length p <= 0 ? n : n * 10**p end |