Sha256: 169b197fd7c6634229da72a88f78f27a5e9ffba00a45812f37c1d0084c17843c

Contents?: true

Size: 464 Bytes

Versions: 24

Compression:

Stored size: 464 Bytes

Contents

class Infobar::Frequency
  def initialize(duration)
    @duration = duration.to_f
    @called   = 0
  end

  attr_reader :duration

  attr_reader :called

  def update(now: Time.now)
    @update = now
    @called += 1
  end

  def call(&block)
    now = Time.now
    if !@update || now - @update > @duration
      update now: now
      block.call
    end
  end

  def reset
    @update = nil
    @called = 0
    self
  end

  def to_s
    @duration.to_s
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
infobar-0.8.1 lib/infobar/frequency.rb
infobar-0.8.0 lib/infobar/frequency.rb
infobar-0.7.4 lib/infobar/frequency.rb
infobar-0.7.2 lib/infobar/frequency.rb
infobar-0.7.1 lib/infobar/frequency.rb
infobar-0.7.0 lib/infobar/frequency.rb
infobar-0.6.2 lib/infobar/frequency.rb
infobar-0.6.1 lib/infobar/frequency.rb
infobar-0.6.0 lib/infobar/frequency.rb
infobar-0.5.1 lib/infobar/frequency.rb
infobar-0.5.0 lib/infobar/frequency.rb
infobar-0.4.0 lib/infobar/frequency.rb
infobar-0.3.0 lib/infobar/frequency.rb
infobar-0.2.0 lib/infobar/frequency.rb
infobar-0.1.1 lib/infobar/frequency.rb
infobar-0.1.0 lib/infobar/frequency.rb
infobar-0.0.7 lib/infobar/frequency.rb
infobar-0.0.6 lib/infobar/frequency.rb
infobar-0.0.5 lib/infobar/frequency.rb
infobar-0.0.4 lib/infobar/frequency.rb