Class: Topaz::Clock::Event
- Inherits:
-
Object
- Object
- Topaz::Clock::Event
- Defined in:
- lib/topaz/clock.rb
Overview
Clock events
Instance Attribute Summary collapse
-
#clock ⇒ Object
Returns the value of attribute clock.
Instance Method Summary collapse
- #do_clock ⇒ Array
- #do_start ⇒ Array
- #do_stop ⇒ Array
- #do_tick ⇒ Array
-
#initialize ⇒ Event
constructor
A new instance of Event.
-
#start(&callback) ⇒ Array<Proc>
Pass in a callback that is called when start is called.
-
#stop(&callback) ⇒ Array<Proc>
pass in a callback that is called when stop is called.
-
#tick(&callback) ⇒ Array<Proc>
Pass in a callback which will be fired on each tick.
Constructor Details
#initialize ⇒ Event
123 124 125 126 127 |
# File 'lib/topaz/clock.rb', line 123 def initialize @start = [] @stop = [] @tick = [] end |
Instance Attribute Details
#clock ⇒ Object
Returns the value of attribute clock.
121 122 123 |
# File 'lib/topaz/clock.rb', line 121 def clock @clock end |
Instance Method Details
#do_clock ⇒ Array
130 131 132 |
# File 'lib/topaz/clock.rb', line 130 def do_clock !@clock.nil? && @clock.call end |
#do_start ⇒ Array
146 147 148 |
# File 'lib/topaz/clock.rb', line 146 def do_start @start.map(&:call) end |
#do_stop ⇒ Array
162 163 164 |
# File 'lib/topaz/clock.rb', line 162 def do_stop @stop.map(&:call) end |
#do_tick ⇒ Array
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 |