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.


354
355
356
357
358
359
360
# File 'lib/puppet/pops/time/timespan.rb', line 354

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


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

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


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

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

#create_formatObject


362
363
364
365
366
367
368
369
370
371
# File 'lib/puppet/pops/time/timespan.rb', line 362

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

#multiplierObject


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

def multiplier
  0
end

#nanoseconds(group) ⇒ Object


395
396
397
# File 'lib/puppet/pops/time/timespan.rb', line 395

def nanoseconds(group)
  group.to_i * multiplier
end

#set_use_totalObject


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

def set_use_total
  @use_total = true
end

#use_total?Boolean

Returns:

  • (Boolean)

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

def use_total?
  @use_total
end