Class: ProgressBar::Components::Rate
- Inherits:
-
Object
- Object
- ProgressBar::Components::Rate
- Includes:
- Progressable, Timer
- Defined in:
- lib/ruby-progressbar/components/rate.rb
Defined Under Namespace
Classes: As
Constant Summary
Constants included from Progressable
Progressable::DEFAULT_BEGINNING_POSITION, Progressable::DEFAULT_SMOOTHING, Progressable::DEFAULT_TOTAL
Constants included from Timer
Instance Attribute Summary collapse
-
#rate_scale ⇒ Object
Returns the value of attribute rate_scale.
Attributes included from Progressable
#autofinish, #finished, #progress, #running_average, #smoothing, #starting_position, #total
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Rate
constructor
A new instance of Rate.
- #reset ⇒ Object
- #start(options = {}) ⇒ Object
- #to_s(format_string = "%i") ⇒ Object
Methods included from Progressable
#decrement, #finish, #finished?, #increment, #percentage_completed, #percentage_completed_with_precision, #progress_made, #started?
Methods included from Timer
#pause, #resume, #started?, #stop, #stopped?
Constructor Details
#initialize(options = {}) ⇒ Rate
Returns a new instance of Rate.
9 10 11 12 13 14 15 |
# File 'lib/ruby-progressbar/components/rate.rb', line 9 def initialize( = {}) self.rate_scale = [:rate_scale] @started_at = nil @stopped_at = nil super end |
Instance Attribute Details
#rate_scale ⇒ Object
Returns the value of attribute rate_scale.
7 8 9 |
# File 'lib/ruby-progressbar/components/rate.rb', line 7 def rate_scale @rate_scale end |
Instance Method Details
#reset ⇒ Object
22 23 24 25 |
# File 'lib/ruby-progressbar/components/rate.rb', line 22 def reset as(Timer).reset as(Progressable).reset end |
#start(options = {}) ⇒ Object
17 18 19 20 |
# File 'lib/ruby-progressbar/components/rate.rb', line 17 def start( = {}) as(Timer).start as(Progressable).start() end |
#to_s(format_string = "%i") ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby-progressbar/components/rate.rb', line 27 def to_s(format_string = "%i") elapsed = elapsed_whole_seconds.to_f return 0 unless elapsed > 0 base_rate = (progress_made / elapsed) if rate_scale scaled_rate = rate_scale.call(base_rate) else scaled_rate = base_rate end format_string % scaled_rate end |