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



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

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

Instance Attribute Details

#clockObject

Returns the value of attribute clock.



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

def clock
  @clock
end

Instance Method Details

#do_clockArray



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

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

#do_startArray



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

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

#do_stopArray



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

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

#do_tickArray



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

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

#start(&callback) ⇒ Array<Proc>

Pass in a callback that is called when start is called



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

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



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

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



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

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