Class: Gem::StreamUI::VerboseDownloadReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/user_interaction.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out_stream, *args) ⇒ VerboseDownloadReporter

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



593
594
595
596
# File 'lib/rubygems/user_interaction.rb', line 593

def initialize(out_stream, *args)
  @out = out_stream
  @progress = 0
end

Instance Attribute Details

#file_nameObject (readonly)

The current file name being displayed



577
578
579
# File 'lib/rubygems/user_interaction.rb', line 577

def file_name
  @file_name
end

#progressObject (readonly)

The current progress (0 to 100)



587
588
589
# File 'lib/rubygems/user_interaction.rb', line 587

def progress
  @progress
end

#total_bytesObject (readonly)

The total bytes in the file



582
583
584
# File 'lib/rubygems/user_interaction.rb', line 582

def total_bytes
  @total_bytes
end

Instance Method Details

#doneObject

Indicates the download is complete.



629
630
631
632
# File 'lib/rubygems/user_interaction.rb', line 629

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.



602
603
604
605
606
607
608
# File 'lib/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) ⇒ Object

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



613
614
615
616
617
618
619
620
621
622
623
624
# File 'lib/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