Class: LibGems::StreamUI::VerboseDownloadReporter
- Inherits:
-
Object
- Object
- LibGems::StreamUI::VerboseDownloadReporter
- Defined in:
- lib/libgems/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.
450 451 452 453 |
# File 'lib/libgems/user_interaction.rb', line 450 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.
448 449 450 |
# File 'lib/libgems/user_interaction.rb', line 448 def file_name @file_name end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
448 449 450 |
# File 'lib/libgems/user_interaction.rb', line 448 def progress @progress end |
#total_bytes ⇒ Object (readonly)
Returns the value of attribute total_bytes.
448 449 450 |
# File 'lib/libgems/user_interaction.rb', line 448 def total_bytes @total_bytes end |
Instance Method Details
#done ⇒ Object
476 477 478 479 |
# File 'lib/libgems/user_interaction.rb', line 476 def done @progress = 100 if @units == '%' update_display(true, true) end |
#fetch(file_name, total_bytes) ⇒ Object
455 456 457 458 459 460 461 |
# File 'lib/libgems/user_interaction.rb', line 455 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
463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'lib/libgems/user_interaction.rb', line 463 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 |