A progress reporter that prints out messages about the current progress.
Attributes
Read
The current file name being displayed
Read
The total bytes in the file
Read
The current progress (0 to 100)
Class Methods
lib/rubygems/user_interaction.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/rubygems/user_interaction.rb, line 602
def initialize(out_stream, *args)
@out = out_stream
@progress = 0
end
Creates a new verbose download reporter that will display on out_stream
. The other arguments are ignored.
Instance Methods
#
lib/rubygems/user_interaction.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/rubygems/user_interaction.rb, line 638
def done
@progress = 100 if @units == '%'
update_display(true, true)
end
Indicates the download is complete.
lib/rubygems/user_interaction.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/rubygems/user_interaction.rb, line 611
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
Tells the download reporter that the file_name
is being fetched and contains total_bytes
.
lib/rubygems/user_interaction.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/rubygems/user_interaction.rb, line 622
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
Updates the verbose download reporter for the given number of bytes
.