Class: Gem::StreamUI::VerboseDownloadReporter
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rubygems/user_interaction.rb |
Overview
A progress reporter that prints out messages about the current progress.
Class Method Summary
-
.new(out_stream, *args) ⇒ VerboseDownloadReporter
constructor
Creates a new verbose download reporter that will display on
out_stream
.
Instance Attribute Summary
-
#file_name
readonly
The current file name being displayed.
-
#progress
readonly
The current progress (0 to 100).
-
#total_bytes
readonly
The total bytes in the file.
Instance Method Summary
-
#done
Indicates the download is complete.
-
#fetch(file_name, total_bytes)
Tells the download reporter that the #file_name is being fetched and contains #total_bytes.
-
#update(bytes)
Updates the verbose download reporter for the given number of
bytes
. - #update_display(show_progress = true, new_line = false) private Internal use only
Constructor Details
.new(out_stream, *args) ⇒ VerboseDownloadReporter
Creates a new verbose download reporter that will display on out_stream
. The other arguments are ignored.
# File 'lib/rubygems/user_interaction.rb', line 604
def initialize(out_stream, *args) @out = out_stream @progress = 0 end
Instance Attribute Details
#file_name (readonly)
The current file name being displayed
# File 'lib/rubygems/user_interaction.rb', line 588
attr_reader :file_name
#progress (readonly)
The current progress (0 to 100)
# File 'lib/rubygems/user_interaction.rb', line 598
attr_reader :progress
#total_bytes (readonly)
The total bytes in the file
# File 'lib/rubygems/user_interaction.rb', line 593
attr_reader :total_bytes
Instance Method Details
#done
Indicates the download is complete.
# File 'lib/rubygems/user_interaction.rb', line 640
def done @progress = 100 if @units == '%' update_display(true, true) end
#fetch(file_name, total_bytes)
Tells the download reporter that the #file_name is being fetched and contains #total_bytes.
# File 'lib/rubygems/user_interaction.rb', line 613
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)
Updates the verbose download reporter for the given number of bytes
.
# File 'lib/rubygems/user_interaction.rb', line 624
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
#update_display(show_progress = true, new_line = false) (private)
# File 'lib/rubygems/user_interaction.rb', line 647
def update_display(show_progress = true, new_line = false) # :nodoc: return unless @out.tty? if show_progress then @out.print "\rFetching: %s (%3d%s)" % [@file_name, @progress, @units] else @out.print "Fetching: %s" % @file_name end @out.puts if new_line end