Class: ProgressBar::Projectors::SmoothedAverage
- Inherits:
-
Object
- Object
- ProgressBar::Projectors::SmoothedAverage
- Defined in:
- lib/ruby-progressbar/projectors/smoothed_average.rb
Constant Summary collapse
- DEFAULT_STRENGTH =
0.1
- DEFAULT_BEGINNING_POSITION =
0
Instance Attribute Summary collapse
-
#projection ⇒ Object
readonly
Returns the value of attribute projection.
-
#samples ⇒ Object
Returns the value of attribute samples.
-
#strength ⇒ Object
Returns the value of attribute strength.
Class Method Summary collapse
Instance Method Summary collapse
- #decrement ⇒ Object
- #increment ⇒ Object
-
#initialize(options = {}) ⇒ SmoothedAverage
constructor
A new instance of SmoothedAverage.
- #none? ⇒ Boolean
- #progress ⇒ Object
- #progress=(new_progress) ⇒ Object
- #reset ⇒ Object
- #start(options = {}) ⇒ Object
- #total=(_new_total) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SmoothedAverage
Returns a new instance of SmoothedAverage.
11 12 13 14 15 16 17 |
# File 'lib/ruby-progressbar/projectors/smoothed_average.rb', line 11 def initialize( = {}) self.samples = [] self.projection = 0.0 self.strength = [:strength] || DEFAULT_STRENGTH start(:at => DEFAULT_BEGINNING_POSITION) end |
Instance Attribute Details
#projection ⇒ Object
Returns the value of attribute projection.
9 10 11 |
# File 'lib/ruby-progressbar/projectors/smoothed_average.rb', line 9 def projection @projection end |
#samples ⇒ Object
Returns the value of attribute samples.
7 8 9 |
# File 'lib/ruby-progressbar/projectors/smoothed_average.rb', line 7 def samples @samples end |
#strength ⇒ Object
Returns the value of attribute strength.
7 8 9 |
# File 'lib/ruby-progressbar/projectors/smoothed_average.rb', line 7 def strength @strength end |
Class Method Details
.calculate(current_projection, new_value, rate) ⇒ Object
56 57 58 |
# 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 |
Instance Method Details
#decrement ⇒ Object
24 25 26 |
# File 'lib/ruby-progressbar/projectors/smoothed_average.rb', line 24 def decrement self.progress -= 1 end |
#increment ⇒ Object
28 29 30 |
# File 'lib/ruby-progressbar/projectors/smoothed_average.rb', line 28 def increment self.progress += 1 end |
#none? ⇒ Boolean
52 53 54 |
# File 'lib/ruby-progressbar/projectors/smoothed_average.rb', line 52 def none? projection.zero? end |
#progress ⇒ Object
32 33 34 |
# File 'lib/ruby-progressbar/projectors/smoothed_average.rb', line 32 def progress samples[1] end |
#progress=(new_progress) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# 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 ⇒ Object
38 39 40 |
# File 'lib/ruby-progressbar/projectors/smoothed_average.rb', line 38 def reset start(:at => samples[0]) end |
#start(options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/ruby-progressbar/projectors/smoothed_average.rb', line 19 def start( = {}) self.projection = 0.0 self.progress = samples[0] = ([:at] || progress) end |
#total=(_new_total) ⇒ Object
36 |
# File 'lib/ruby-progressbar/projectors/smoothed_average.rb', line 36 def total=(_new_total); end |