In Files

  • rubygems/user_interaction.rb

Parent

Class/Module Index [+]

Quicksearch

Gem::StreamUI::VerboseDownloadReporter

A progress reporter that prints out messages about the current progress.

Attributes

file_name[R]

The current file name being displayed

progress[R]

The current progress (0 to 100)

total_bytes[R]

The total bytes in the file

Public Class Methods

new(out_stream, *args) click to toggle source

Creates a new verbose download reporter that will display on out_stream. The other arguments are ignored.

 
               # File rubygems/user_interaction.rb, line 593
def initialize(out_stream, *args)
  @out = out_stream
  @progress = 0
end
            

Public Instance Methods

done() click to toggle source

Indicates the download is complete.

 
               # File rubygems/user_interaction.rb, line 629
def done
  @progress = 100 if @units == '%'
  update_display(true, true)
end
            
fetch(file_name, total_bytes) click to toggle source

Tells the download reporter that the file_name is being fetched and contains total_bytes.

 
               # File rubygems/user_interaction.rb, line 602
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

Updates the verbose download reporter for the given number of bytes.

 
               # File rubygems/user_interaction.rb, line 613
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
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus