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
The current file name being displayed.
-
#progress ⇒ Object
readonly
The current progress (0 to 100).
-
#total_bytes ⇒ Object
readonly
The total bytes in the file.
Instance Method Summary collapse
-
#done ⇒ Object
Indicates the download is complete.
-
#fetch(file_name, total_bytes) ⇒ Object
Tells the download reporter that the
file_name
is being fetched and containstotal_bytes
. -
#initialize(out_stream, *args) ⇒ VerboseDownloadReporter
constructor
Creates a new verbose download reporter that will display on
out_stream
. -
#update(bytes) ⇒ Object
Updates the verbose download reporter for the given number of
bytes
.
Constructor Details
#initialize(out_stream, *args) ⇒ VerboseDownloadReporter
Creates a new verbose download reporter that will display on out_stream
. The other arguments are ignored.
597 598 599 600 |
# File 'lib/rubygems/user_interaction.rb', line 597 def initialize(out_stream, *args) @out = out_stream @progress = 0 end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
The current file name being displayed
581 582 583 |
# File 'lib/rubygems/user_interaction.rb', line 581 def file_name @file_name end |
#progress ⇒ Object (readonly)
The current progress (0 to 100)
591 592 593 |
# File 'lib/rubygems/user_interaction.rb', line 591 def progress @progress end |
#total_bytes ⇒ Object (readonly)
The total bytes in the file
586 587 588 |
# File 'lib/rubygems/user_interaction.rb', line 586 def total_bytes @total_bytes end |
Instance Method Details
#done ⇒ Object
Indicates the download is complete.
633 634 635 636 |
# File 'lib/rubygems/user_interaction.rb', line 633 def done @progress = 100 if @units == '%' update_display(true, true) end |
#fetch(file_name, total_bytes) ⇒ Object
Tells the download reporter that the file_name
is being fetched and contains total_bytes
.
606 607 608 609 610 611 612 |
# File 'lib/rubygems/user_interaction.rb', line 606 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
Updates the verbose download reporter for the given number of bytes
.
617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/rubygems/user_interaction.rb', line 617 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 |