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
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
#clock ⇒ Object
Returns the value of attribute clock.
122 123 124 |
# File 'lib/topaz/clock.rb', line 122 def clock @clock end |
Instance Method Details
#do_clock ⇒ Array
131 132 133 |
# File 'lib/topaz/clock.rb', line 131 def do_clock !@clock.nil? && @clock.call end |
#do_start ⇒ Array
147 148 149 |
# File 'lib/topaz/clock.rb', line 147 def do_start @start.map(&:call) end |
#do_stop ⇒ Array
163 164 165 |
# File 'lib/topaz/clock.rb', line 163 def do_stop @stop.map(&:call) end |
#do_tick ⇒ 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
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
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
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 |