class ProgressBar::Components::Rate

Attributes

progress[RW]
rate_scale[RW]
timer[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/ruby-progressbar/components/rate.rb, line 8
def initialize(options = {})
  self.rate_scale = options[:rate_scale] || lambda { |x| x }
  self.timer      = options[:timer]
  self.progress   = options[:progress]
end

Public Instance Methods

rate_of_change(format_string = '%i') click to toggle source
# File lib/ruby-progressbar/components/rate.rb, line 14
def rate_of_change(format_string = '%i')
  return '0' if elapsed_seconds <= 0

  format_string % scaled_rate
end
rate_of_change_with_precision() click to toggle source
# File lib/ruby-progressbar/components/rate.rb, line 20
def rate_of_change_with_precision
  rate_of_change('%.2f')
end

Private Instance Methods

base_rate() click to toggle source
# File lib/ruby-progressbar/components/rate.rb, line 30
def base_rate
  progress.absolute / elapsed_seconds
end
elapsed_seconds() click to toggle source
# File lib/ruby-progressbar/components/rate.rb, line 34
def elapsed_seconds
  timer.elapsed_whole_seconds.to_f
end
scaled_rate() click to toggle source
# File lib/ruby-progressbar/components/rate.rb, line 26
def scaled_rate
  rate_scale.call(base_rate)
end