Class: TreasureData::Command::SizeBasedDownloadProgressIndicator
- Inherits:
-
DownloadProgressIndicator
- Object
- DownloadProgressIndicator
- TreasureData::Command::SizeBasedDownloadProgressIndicator
- Defined in:
- lib/td/command/common.rb
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(msg, size, perc_step = 1, min_periodicity = nil) ⇒ SizeBasedDownloadProgressIndicator
constructor
A new instance of SizeBasedDownloadProgressIndicator.
- #update(curr_size) ⇒ Object
Constructor Details
#initialize(msg, size, perc_step = 1, min_periodicity = nil) ⇒ SizeBasedDownloadProgressIndicator
Returns a new instance of SizeBasedDownloadProgressIndicator.
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/td/command/common.rb', line 361 def initialize(msg, size, perc_step = 1, min_periodicity = nil) @size = size # perc_step is how small a percentage increment can be shown @perc_step = perc_step # min_periodicity=X limits updates to one every X second @start_time = Time.now.to_i @min_periodicity = min_periodicity # track progress @last_perc_step = 0 @last_time = @start_time super(msg) end |
Instance Method Details
#finish ⇒ Object
399 400 401 |
# File 'lib/td/command/common.rb', line 399 def finish print "\r#{@base_msg}...done" + " " * 20 end |
#update(curr_size) ⇒ Object
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/td/command/common.rb', line 378 def update(curr_size) if @size.nil? || @size == 0 msg = "\r#{@base_msg}: #{Command.humanize_bytesize(curr_size)}" print msg true else ratio = (curr_size.to_f * 100 / @size).round(1) if ratio >= (@last_perc_step + @perc_step) && (!@min_periodicity || (time = Time.now.to_i) - @last_time >= @min_periodicity) msg = "\r#{@base_msg}: #{Command.humanize_bytesize(curr_size)} / #{ratio}%" print "\r" + " " * (msg.length + 10) print msg @last_perc_step = ratio @last_time = time true else false end end end |