| Class | Gem::StreamUI::VerboseDownloadReporter |
| In: |
lib/rubygems/user_interaction.rb
|
| Parent: | Object |
A progress reporter that prints out messages about the current progress.
| file_name | [R] | |
| progress | [R] | |
| total_bytes | [R] |
# File lib/rubygems/user_interaction.rb, line 480
480: def initialize(out_stream, *args)
481: @out = out_stream
482: @progress = 0
483: end
# File lib/rubygems/user_interaction.rb, line 506
506: def done
507: @progress = 100 if @units == '%'
508: update_display(true, true)
509: end
# File lib/rubygems/user_interaction.rb, line 485
485: def fetch(file_name, total_bytes)
486: @file_name = file_name
487: @total_bytes = total_bytes.to_i
488: @units = @total_bytes.zero? ? 'B' : '%'
489:
490: update_display(false)
491: end
# File lib/rubygems/user_interaction.rb, line 493
493: def update(bytes)
494: new_progress = if @units == 'B' then
495: bytes
496: else
497: ((bytes.to_f * 100) / total_bytes.to_f).ceil
498: end
499:
500: return if new_progress == @progress
501:
502: @progress = new_progress
503: update_display
504: end