Class: Topaz::Clock::EventTrigger

Inherits:
Object
  • Object
show all
Defined in:
lib/topaz/clock.rb

Overview

Trigger clock events

Instance Method Summary collapse

Constructor Details

#initializeEventTrigger

Returns a new instance of EventTrigger.



96
97
98
# File 'lib/topaz/clock.rb', line 96

def initialize
  @stop = []
end

Instance Method Details

#stop(&callback) ⇒ Array<Proc>

Pass in a callback which will stop the clock if it evaluates to true

Parameters:

  • callback (Proc)

Returns:

  • (Array<Proc>)


103
104
105
106
107
108
109
# File 'lib/topaz/clock.rb', line 103

def stop(&callback)
  if block_given?
    @stop.clear
    @stop << callback
  end
  @stop
end

#stop?Boolean

Should the stop event be triggered?

Returns:

  • (Boolean)


113
114
115
# File 'lib/topaz/clock.rb', line 113

def stop?
  !@stop.nil? && @stop.any?(&:call)
end