Class: Gem::StreamUI::VerboseDownloadReporter
- Inherits:
-
Object
- Object
- Gem::StreamUI::VerboseDownloadReporter
- Defined in:
- lib/rubygems/user_interaction.rb
Overview
A progress reporter that prints out messages about the current progress.
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
-
#total_bytes ⇒ Object
readonly
Returns the value of attribute total_bytes.
Instance Method Summary collapse
- #done ⇒ Object
- #fetch(file_name, total_bytes) ⇒ Object
-
#initialize(out_stream, *args) ⇒ VerboseDownloadReporter
constructor
A new instance of VerboseDownloadReporter.
- #update(bytes) ⇒ Object
Constructor Details
#initialize(out_stream, *args) ⇒ VerboseDownloadReporter
Returns a new instance of VerboseDownloadReporter.
480 481 482 483 |
# File 'lib/rubygems/user_interaction.rb', line 480 def initialize(out_stream, *args) @out = out_stream @progress = 0 end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
478 479 480 |
# File 'lib/rubygems/user_interaction.rb', line 478 def file_name @file_name end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
478 479 480 |
# File 'lib/rubygems/user_interaction.rb', line 478 def progress @progress end |
#total_bytes ⇒ Object (readonly)
Returns the value of attribute total_bytes.
478 479 480 |
# File 'lib/rubygems/user_interaction.rb', line 478 def total_bytes @total_bytes end |
Instance Method Details
#done ⇒ Object
506 507 508 509 |
# File 'lib/rubygems/user_interaction.rb', line 506 def done @progress = 100 if @units == '%' update_display(true, true) end |
#fetch(file_name, total_bytes) ⇒ Object
485 486 487 488 489 490 491 |
# File 'lib/rubygems/user_interaction.rb', line 485 def fetch(file_name, total_bytes) @file_name = file_name @total_bytes = total_bytes.to_i @units = @total_bytes.zero? ? 'B' : '%' update_display(false) end |
#update(bytes) ⇒ Object
493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/rubygems/user_interaction.rb', line 493 def update(bytes) new_progress = if @units == 'B' then bytes else ((bytes.to_f * 100) / total_bytes.to_f).ceil end return if new_progress == @progress @progress = new_progress update_display end |