Class: EasyTimers::Timer
- Inherits:
-
Object
- Object
- EasyTimers::Timer
- Defined in:
- lib/easy_timers/timer.rb
Overview
Wraps a timer
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#recurring ⇒ Object
readonly
Returns the value of attribute recurring.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
-
#cancel ⇒ Object
Cancel the timer by overwriting the callback.
-
#cancelled? ⇒ Boolean
Check if this timer has been cancelled.
-
#initialize(time, name, interval, recurring, callback) ⇒ Timer
constructor
Create a new instance.
Constructor Details
#initialize(time, name, interval, recurring, callback) ⇒ Timer
Create a new instance
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/easy_timers/timer.rb', line 15 def initialize(time, name, interval, recurring, callback) @time = time @name = name @interval = interval @recurring = recurring @callback = callback @cancelled = false if @name == nil @name = Time.now.gmtime.to_f.to_s.to_sym end end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
7 8 9 |
# File 'lib/easy_timers/timer.rb', line 7 def callback @callback end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
7 8 9 |
# File 'lib/easy_timers/timer.rb', line 7 def interval @interval end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/easy_timers/timer.rb', line 7 def name @name end |
#recurring ⇒ Object (readonly)
Returns the value of attribute recurring.
7 8 9 |
# File 'lib/easy_timers/timer.rb', line 7 def recurring @recurring end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
7 8 9 |
# File 'lib/easy_timers/timer.rb', line 7 def time @time end |
Instance Method Details
#cancel ⇒ Object
Cancel the timer by overwriting the callback
30 31 32 33 |
# File 'lib/easy_timers/timer.rb', line 30 def cancel() @callback = nil @cancelled = true end |
#cancelled? ⇒ Boolean
Check if this timer has been cancelled.
37 38 39 |
# File 'lib/easy_timers/timer.rb', line 37 def cancelled? return @cancelled end |