Class: TreasureData::Command::TimeBasedDownloadProgressIndicator

Inherits:
DownloadProgressIndicator 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.



362
363
364
365
366
367
# File 'lib/td/command/common.rb', line 362

def initialize(msg, start_time, periodicity = 2)
  @start_time = start_time
  @last_time = start_time
  @periodicity = periodicity
  super(msg)
end

Instance Method Details

#finishObject



381
382
383
# File 'lib/td/command/common.rb', line 381

def finish
  $stdout.puts "\r#{@base_msg}...done" + " " * 20
end

#updateObject



369
370
371
372
373
374
375
376
377
378
379
# File 'lib/td/command/common.rb', line 369

def update
  if (time = Time.now.to_i) - @last_time >= @periodicity
    msg = "\r#{@base_msg}: #{Command.humanize_elapsed_time(@start_time, time)} elapsed"
    $stdout.print "\r" + " " * (msg.length + 10)
    $stdout.print msg
    @last_time = time
    true
  else
    false
  end
end