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

Returns a new instance of VerboseDownloadReporter.



490
491
492
493
# File 'lib/rubygems/user_interaction.rb', line 490

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

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name



488
489
490
# File 'lib/rubygems/user_interaction.rb', line 488

def file_name
  @file_name
end

#progressObject (readonly)

Returns the value of attribute progress



488
489
490
# File 'lib/rubygems/user_interaction.rb', line 488

def progress
  @progress
end

#total_bytesObject (readonly)

Returns the value of attribute total_bytes



488
489
490
# File 'lib/rubygems/user_interaction.rb', line 488

def total_bytes
  @total_bytes
end

Instance Method Details

#doneObject



516
517
518
519
# File 'lib/rubygems/user_interaction.rb', line 516

def done
  @progress = 100 if @units == '%'
  update_display(true, true)
end

#fetch(file_name, total_bytes) ⇒ Object



495
496
497
498
499
500
501
# 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) ⇒ Object



503
504
505
506
507
508
509
510
511
512
513
514
# 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