Class: Anorexic::TimedEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/anorexic/base/timers.rb

Overview

This class is used by Anorexic to hold events and push them into the events stack when the time comes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seconds, repeat, handler, args, block) ⇒ TimedEvent

Returns a new instance of TimedEvent.


17
18
19
20
# File 'lib/anorexic/base/timers.rb', line 17

def initialize seconds, repeat, handler, args, block
  @time = Time.now + seconds
  @seconds, @repeat, @handler, @args, @block  = seconds, repeat, handler, args, block
end

Instance Attribute Details

#timedObject (readonly)

Returns the value of attribute timed


34
35
36
# File 'lib/anorexic/base/timers.rb', line 34

def timed
  @timed
end

Instance Method Details

#done?Boolean

Returns:

  • (Boolean)

22
23
24
25
26
27
28
# File 'lib/anorexic/base/timers.rb', line 22

def done?
  return false unless @time <= Time.now
  Anorexic.push_event @handler, *@args, &@block
  return true unless @repeat
  @time = Time.now + @seconds
  false
end

#stop_repeatObject


30
31
32
# File 'lib/anorexic/base/timers.rb', line 30

def stop_repeat
  @repeat = false
end