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.
596 597 598 599 |
# File 'lib/rubygems/user_interaction.rb', line 596 def initialize(out_stream, *args) @out = out_stream @progress = 0 end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
The current file name being displayed
580 581 582 |
# File 'lib/rubygems/user_interaction.rb', line 580 def file_name @file_name end |
#progress ⇒ Object (readonly)
The current progress (0 to 100)
590 591 592 |
# File 'lib/rubygems/user_interaction.rb', line 590 def progress @progress end |
#total_bytes ⇒ Object (readonly)
The total bytes in the file
585 586 587 |
# File 'lib/rubygems/user_interaction.rb', line 585 def total_bytes @total_bytes end |
Instance Method Details
#done ⇒ Object
Indicates the download is complete.
632 633 634 635 |
# File 'lib/rubygems/user_interaction.rb', line 632 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
.
605 606 607 608 609 610 611 |
# File 'lib/rubygems/user_interaction.rb', line 605 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
.
616 617 618 619 620 621 622 623 624 625 626 627 |
# File 'lib/rubygems/user_interaction.rb', line 616 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 |