class Gem::StreamUI::VerboseDownloadReporter
A progress reporter that prints out messages about the current progress.
Attributes
file_name[R]
progress[R]
total_bytes[R]
Public Class Methods
new(out_stream, *args)
click to toggle source
# File lib/rubygems/user_interaction.rb, line 490 def initialize(out_stream, *args) @out = out_stream @progress = 0 end
Public Instance Methods
done()
click to toggle source
# File lib/rubygems/user_interaction.rb, line 516 def done @progress = 100 if @units == '%' update_display(true, true) end
fetch(file_name, total_bytes)
click to toggle source
# File lib/rubygems/user_interaction.rb, line 495 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)
click to toggle source
# File lib/rubygems/user_interaction.rb, line 503 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
Private Instance Methods
update_display(show_progress = true, new_line = false)
click to toggle source
# File lib/rubygems/user_interaction.rb, line 523 def update_display(show_progress = true, new_line = false) 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