Class: Puppet::Pops::Time::Timespan::Format::ValueSegment

Inherits:
Segment
  • Object
show all
Defined in:
lib/puppet/pops/time/timespan.rb

Instance Method Summary collapse

Methods inherited from Segment

#append_to

Constructor Details

#initialize(padchar, width, default_width) ⇒ ValueSegment

Returns a new instance of ValueSegment.



357
358
359
360
361
362
363
# File 'lib/puppet/pops/time/timespan.rb', line 357

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



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/puppet/pops/time/timespan.rb', line 376

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



414
415
416
# File 'lib/puppet/pops/time/timespan.rb', line 414

def append_value(bld, n)
  bld << sprintf(@format, n)
end

#create_formatObject



365
366
367
368
369
370
371
372
373
374
# File 'lib/puppet/pops/time/timespan.rb', line 365

def create_format
  case @padchar
  when nil
    '%d'
  when ' '
    "%#{@width || @default_width}d"
  else
    "%#{@padchar}#{@width || @default_width}d"
  end
end

#multiplierObject



402
403
404
# File 'lib/puppet/pops/time/timespan.rb', line 402

def multiplier
  0
end

#nanoseconds(group) ⇒ Object



398
399
400
# File 'lib/puppet/pops/time/timespan.rb', line 398

def nanoseconds(group)
  group.to_i * multiplier
end

#set_use_totalObject



406
407
408
# File 'lib/puppet/pops/time/timespan.rb', line 406

def set_use_total
  @use_total = true
end

#use_total?Boolean

Returns:

  • (Boolean)


410
411
412
# File 'lib/puppet/pops/time/timespan.rb', line 410

def use_total?
  @use_total
end