Class: TreasureData::Command::TimeBasedDownloadProgressIndicator

Inherits:
Object
  • Object
show all
Defined in:
lib/td/command/common.rb

Instance Method Summary collapse

Constructor Details

#initialize(msg, start_time, periodicity = 2) ⇒ TimeBasedDownloadProgressIndicator

Returns a new instance of TimeBasedDownloadProgressIndicator.



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/td/command/common.rb', line 387

def initialize(msg, start_time, periodicity = 2)
  require 'ruby-progressbar'

  @start_time = start_time
  @last_time = start_time
  @periodicity = periodicity

  @progress_bar = ProgressBar.create(
    title: msg,
    total: nil,
    format: formated_with_elasped_time(0),
    output: $stdout,
    unknown_progress_animation_steps: [' '],
  )

  update_progress_bar(formated_with_elasped_time(Command.humanize_elapsed_time(@start_time, @start_time)))
end

Instance Method Details

#finishObject



415
416
417
418
# File 'lib/td/command/common.rb', line 415

def finish
  # NOTE %B is for clear terminal line
  update_progress_bar("%t: done %B")
end

#updateObject



405
406
407
408
409
410
411
412
413
# File 'lib/td/command/common.rb', line 405

def update
  if (time = Time.now.to_i) - @last_time >= @periodicity
    update_progress_bar(formated_with_elasped_time(Command.humanize_elapsed_time(@start_time, time)))
    @last_time = time
    true
  else
    false
  end
end