class Aspera::Cli::Listener::Progress

a listener to FASP event that displays a progress bar

Constants

BYTE_PER_MEGABIT

Public Class Methods

new() click to toggle source
# File lib/aspera/cli/listener/progress.rb, line 9
def initialize
  @progress=nil
  @cumulative=0
end

Public Instance Methods

event_struct(data) click to toggle source
# File lib/aspera/cli/listener/progress.rb, line 16
def event_struct(data)
  case data['Type']
  when 'NOTIFICATION'
    if data.has_key?('PreTransferBytes') then
      @progress=ProgressBar.create(
      :format     => '%a %B %p%% %r Mbps %e',
      :rate_scale => lambda{|rate|rate/BYTE_PER_MEGABIT},
      :title      => 'progress',
      :total      => data['PreTransferBytes'].to_i)
    end
  when 'STOP'
    # stop event when one file is completed
    @cumulative=@cumulative+data['Size'].to_i
  when 'STATS'
    if !@progress.nil? then
      if data.has_key?('Bytescont')
        @progress.progress=@cumulative+data['Bytescont'].to_i
      else
        @progress.progress=data['TransferBytes'].to_i
      end
    else
      puts '.'
    end
  when 'DONE'
    if !@progress.nil? then
      @progress.progress=@progress.total
      @progress=nil
    else
      # terminate progress by going to next line
      puts "\n"
    end
  end
end