Class: Topaz::Clock::Event

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

Overview

Clock events

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEvent

Returns a new instance of Event.



124
125
126
127
128
# File 'lib/topaz/clock.rb', line 124

def initialize
  @start = []
  @stop = []
  @tick = []
end

Instance Attribute Details

#clockObject

Returns the value of attribute clock.



122
123
124
# File 'lib/topaz/clock.rb', line 122

def clock
  @clock
end

Instance Method Details

#do_clockArray

Returns:

  • (Array)


131
132
133
# File 'lib/topaz/clock.rb', line 131

def do_clock
  !@clock.nil? && @clock.call
end

#do_startArray

Returns:

  • (Array)


147
148
149
# File 'lib/topaz/clock.rb', line 147

def do_start
  @start.map(&:call)
end

#do_stopArray

Returns:

  • (Array)


163
164
165
# File 'lib/topaz/clock.rb', line 163

def do_stop
  @stop.map(&:call)
end

#do_tickArray

Returns:

  • (Array)


179
180
181
# File 'lib/topaz/clock.rb', line 179

def do_tick
  @tick.map(&:call)
end

#start(&callback) ⇒ Array<Proc>

Pass in a callback that is called when start is called

Parameters:

  • callback (Proc)

Returns:

  • (Array<Proc>)


138
139
140
141
142
143
144
# File 'lib/topaz/clock.rb', line 138

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

#stop(&callback) ⇒ Array<Proc>

pass in a callback that is called when stop is called

Parameters:

  • callback (Proc)

Returns:

  • (Array<Proc>)


154
155
156
157
158
159
160
# File 'lib/topaz/clock.rb', line 154

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

#tick(&callback) ⇒ Array<Proc>

Pass in a callback which will be fired on each tick

Parameters:

  • callback (Proc)

Returns:

  • (Array<Proc>)


170
171
172
173
174
175
176
# File 'lib/topaz/clock.rb', line 170

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