Class: ProgressBar::Components::Throttle
- Inherits:
-
Object
- Object
- ProgressBar::Components::Throttle
- Includes:
- Timer
- Defined in:
- lib/ruby-progressbar/components/throttle.rb
Constant Summary
Constants included from Timer
ProgressBar::Components::Timer::TIME_FORMAT
Instance Method Summary collapse
- #choke(force = false, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Throttle
constructor
A new instance of Throttle.
Methods included from Timer
#pause, #reset, #resume, #start, #started?, #stop, #stopped?
Constructor Details
#initialize(options = {}) ⇒ Throttle
Returns a new instance of Throttle.
6 7 8 |
# File 'lib/ruby-progressbar/components/throttle.rb', line 6 def initialize( = {}) @period = .delete(:throttle_rate) { 0.01 } || 0.01 end |
Instance Method Details
#choke(force = false, &block) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/ruby-progressbar/components/throttle.rb', line 10 def choke(force = false, &block) if !started? || @period.nil? || force || elapsed_seconds >= @period yield start end end |