Class: ProgressBar::Components::Throttle

Inherits:
Object
  • Object
show all
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

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
9
10
# File 'lib/ruby-progressbar/components/throttle.rb', line 6

def initialize(options = {})
  @period     = options.delete(:throttle_rate) { 0.01 } || 0.01
  @started_at = nil
  @stopped_at = nil
end

Instance Method Details

#choke(force = false, &block) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/ruby-progressbar/components/throttle.rb', line 12

def choke(force = false, &block)
  if !started? || @period.nil? || force || elapsed_seconds >= @period
    yield

    start
  end
end