class ProgressBar::Components::Rate

Attributes

progress[RW]
rate_scale[RW]
started_at[RW]
stopped_at[RW]
timer[RW]

Public Class Methods

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

Private Instance Methods

base_rate() click to toggle source
# File lib/ruby-progressbar/components/rate.rb, line 34
def base_rate
  progress.absolute / elapsed_seconds
end
elapsed_seconds() click to toggle source
# File lib/ruby-progressbar/components/rate.rb, line 38
def elapsed_seconds
  timer.elapsed_whole_seconds.to_f
end
rate_of_change(format_string = '%i') click to toggle source
# File lib/ruby-progressbar/components/rate.rb, line 20
def rate_of_change(format_string = '%i')
  return 0 unless 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 26
def rate_of_change_with_precision
  rate_of_change('%.2f')
end
scaled_rate() click to toggle source
# File lib/ruby-progressbar/components/rate.rb, line 30
def scaled_rate
  rate_scale.call(base_rate)
end