Sha256: af785b24464ce2e6a8ce63b982bafa480d6cfe5a7771373d646fd2480a206f20

Contents?: true

Size: 711 Bytes

Versions: 4342

Compression:

Stored size: 711 Bytes

Contents

class   ProgressBar
module  Components
class   Rate
  attr_accessor :rate_scale,
                :timer,
                :progress

  def initialize(options = {})
    self.rate_scale = options[:rate_scale] || lambda { |x| x }
    self.timer      = options[:timer]
    self.progress   = options[:progress]
  end

  def rate_of_change(format_string = '%i')
    return '0' if elapsed_seconds <= 0

    format_string % scaled_rate
  end

  def rate_of_change_with_precision
    rate_of_change('%.2f')
  end

  private

  def scaled_rate
    rate_scale.call(base_rate)
  end

  def base_rate
    progress.absolute / elapsed_seconds
  end

  def elapsed_seconds
    timer.elapsed_whole_seconds.to_f
  end
end
end
end

Version data entries

4,342 entries across 4,342 versions & 29 rubygems

Version Path
ruby-progressbar-1.13.0rc1 lib/ruby-progressbar/components/rate.rb
ruby-progressbar-1.12.0 lib/ruby-progressbar/components/rate.rb