class ProgressBar::Projectors::SmoothedAverage
Constants
- DEFAULT_BEGINNING_POSITION
- DEFAULT_STRENGTH
Attributes
projection[RW]
samples[RW]
strength[RW]
Public Class Methods
calculate(current_projection, new_value, rate)
click to toggle source
# File lib/ruby-progressbar/projectors/smoothed_average.rb, line 56 def self.calculate(current_projection, new_value, rate) (new_value * (1.0 - rate)) + (current_projection * rate) end
new(options = {})
click to toggle source
# File lib/ruby-progressbar/projectors/smoothed_average.rb, line 11 def initialize(options = {}) self.samples = [] self.projection = 0.0 self.strength = options[:strength] || DEFAULT_STRENGTH start(:at => DEFAULT_BEGINNING_POSITION) end
Public Instance Methods
decrement()
click to toggle source
# File lib/ruby-progressbar/projectors/smoothed_average.rb, line 24 def decrement self.progress -= 1 end
increment()
click to toggle source
# File lib/ruby-progressbar/projectors/smoothed_average.rb, line 28 def increment self.progress += 1 end
none?()
click to toggle source
# File lib/ruby-progressbar/projectors/smoothed_average.rb, line 52 def none? projection.zero? end
progress()
click to toggle source
# File lib/ruby-progressbar/projectors/smoothed_average.rb, line 32 def progress samples[1] end
progress=(new_progress)
click to toggle source
# File lib/ruby-progressbar/projectors/smoothed_average.rb, line 42 def progress=(new_progress) samples[1] = new_progress self.projection = \ self.class.calculate( @projection, absolute, strength ) end
reset()
click to toggle source
# File lib/ruby-progressbar/projectors/smoothed_average.rb, line 38 def reset start(:at => samples[0]) end
start(options = {})
click to toggle source
# File lib/ruby-progressbar/projectors/smoothed_average.rb, line 19 def start(options = {}) self.projection = 0.0 self.progress = samples[0] = (options[:at] || progress) end
total=(_new_total)
click to toggle source
# File lib/ruby-progressbar/projectors/smoothed_average.rb, line 36 def total=(_new_total); end
Private Instance Methods
absolute()
click to toggle source
# File lib/ruby-progressbar/projectors/smoothed_average.rb, line 66 def absolute samples[1] - samples[0] end