Class: Puppet::Pops::Time::Timespan::Format::ValueSegment
Instance Method Summary
collapse
Methods inherited from Segment
#append_to
Constructor Details
#initialize(padchar, width, default_width) ⇒ ValueSegment
Returns a new instance of ValueSegment.
352
353
354
355
356
357
358
|
# File 'lib/puppet/pops/time/timespan.rb', line 352
def initialize(padchar, width, default_width)
@use_total = false
@padchar = padchar
@width = width
@default_width = default_width
@format = create_format
end
|
Instance Method Details
#append_regexp(bld) ⇒ Object
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
# File 'lib/puppet/pops/time/timespan.rb', line 371
def append_regexp(bld)
if @width.nil?
case @padchar
when nil
bld << (use_total? ? '([0-9]+)' : "([0-9]{1,#{@default_width}})")
when '0'
bld << (use_total? ? '([0-9]+)' : "([0-9]{1,#{@default_width}})")
else
bld << (use_total? ? '\s*([0-9]+)' : "([0-9\\s]{1,#{@default_width}})")
end
else
case @padchar
when nil
bld << "([0-9]{1,#{@width}})"
when '0'
bld << "([0-9]{#{@width}})"
else
bld << "([0-9\\s]{#{@width}})"
end
end
end
|
#append_value(bld, n) ⇒ Object
409
410
411
|
# File 'lib/puppet/pops/time/timespan.rb', line 409
def append_value(bld, n)
bld << sprintf(@format, n)
end
|
360
361
362
363
364
365
366
367
368
369
|
# File 'lib/puppet/pops/time/timespan.rb', line 360
def create_format
case @padchar
when nil
'%d'
when ' '
"%#{@width || @default_width}d"
else
"%#{@padchar}#{@width || @default_width}d"
end
end
|
#multiplier ⇒ Object
397
398
399
|
# File 'lib/puppet/pops/time/timespan.rb', line 397
def multiplier
0
end
|
#nanoseconds(group) ⇒ Object
393
394
395
|
# File 'lib/puppet/pops/time/timespan.rb', line 393
def nanoseconds(group)
group.to_i * multiplier
end
|
#set_use_total ⇒ Object
401
402
403
|
# File 'lib/puppet/pops/time/timespan.rb', line 401
def set_use_total
@use_total = true
end
|
#use_total? ⇒ Boolean
405
406
407
|
# File 'lib/puppet/pops/time/timespan.rb', line 405
def use_total?
@use_total
end
|