Module: ProgressBar::Components::Progressable
- Included in:
- Bar, EstimatedTimer
- Defined in:
- lib/progress_bar/components/progressable.rb
Constant Summary collapse
- DEFAULT_TOTAL =
100
- DEFAULT_BEGINNING_POSITION =
0
- DEFAULT_SMOOTHING =
0.1
Instance Attribute Summary collapse
-
#progress ⇒ Object
Returns the value of attribute progress.
-
#running_average ⇒ Object
Returns the value of attribute running_average.
-
#smoothing ⇒ Object
Returns the value of attribute smoothing.
-
#starting_position ⇒ Object
Returns the value of attribute starting_position.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
- #decrement ⇒ Object
- #finish ⇒ Object
- #increment ⇒ Object
- #initialize(options = {}) ⇒ Object
- #percentage_completed ⇒ Object
- #percentage_completed_with_precision ⇒ Object
- #reset ⇒ Object
- #start(options = {}) ⇒ Object
- #started? ⇒ Boolean
Instance Attribute Details
#progress ⇒ Object
Returns the value of attribute progress.
9 10 11 |
# File 'lib/progress_bar/components/progressable.rb', line 9 def progress @progress end |
#running_average ⇒ Object
Returns the value of attribute running_average.
11 12 13 |
# File 'lib/progress_bar/components/progressable.rb', line 11 def running_average @running_average end |
#smoothing ⇒ Object
Returns the value of attribute smoothing.
12 13 14 |
# File 'lib/progress_bar/components/progressable.rb', line 12 def smoothing @smoothing end |
#starting_position ⇒ Object
Returns the value of attribute starting_position.
10 11 12 |
# File 'lib/progress_bar/components/progressable.rb', line 10 def starting_position @starting_position end |
#total ⇒ Object
Returns the value of attribute total.
8 9 10 |
# File 'lib/progress_bar/components/progressable.rb', line 8 def total @total end |
Instance Method Details
#decrement ⇒ Object
36 37 38 |
# File 'lib/progress_bar/components/progressable.rb', line 36 def decrement self.progress -= 1 unless progress == 0 end |
#finish ⇒ Object
57 58 59 |
# File 'lib/progress_bar/components/progressable.rb', line 57 def finish self.progress = self.total end |
#increment ⇒ Object
32 33 34 |
# File 'lib/progress_bar/components/progressable.rb', line 32 def increment self.progress += 1 unless progress == total end |
#initialize(options = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/progress_bar/components/progressable.rb', line 14 def initialize( = {}) self.total = [:total] || DEFAULT_TOTAL self.smoothing = [:smoothing] || DEFAULT_SMOOTHING start :at => DEFAULT_BEGINNING_POSITION end |
#percentage_completed ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/progress_bar/components/progressable.rb', line 61 def percentage_completed # progress / total * 100 # # Doing this way so we can avoid converting each # number to a float and then back to an integer. # self.progress * 100 / total end |
#percentage_completed_with_precision ⇒ Object
70 71 72 |
# File 'lib/progress_bar/components/progressable.rb', line 70 def percentage_completed_with_precision format('%5.2f', (progress.to_f * 100.0 / total * 100.0).floor / 100.0) end |
#reset ⇒ Object
40 41 42 |
# File 'lib/progress_bar/components/progressable.rb', line 40 def reset start :at => self.starting_position end |
#start(options = {}) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/progress_bar/components/progressable.rb', line 21 def start( = {}) self.running_average = 0 self.progress = \ self.starting_position = [:at] || self.progress end |
#started? ⇒ Boolean
28 29 30 |
# File 'lib/progress_bar/components/progressable.rb', line 28 def started? !!self.starting_position end |