Class: UnderOs::Timer
- Inherits:
-
Object
- Object
- UnderOs::Timer
- Defined in:
- lib/under_os/timer.rb
Defined Under Namespace
Classes: Duration
Instance Attribute Summary collapse
-
#_ ⇒ Object
readonly
Returns the value of attribute _.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#repeats ⇒ Object
readonly
Returns the value of attribute repeats.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(seconds, options = {}, &block) ⇒ Timer
constructor
A new instance of Timer.
- #kick ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(seconds, options = {}, &block) ⇒ Timer
Returns a new instance of Timer.
14 15 16 17 18 19 20 21 22 |
# File 'lib/under_os/timer.rb', line 14 def initialize(seconds, ={}, &block) @block = block @counter = [:repeat].to_i if [:repeat].is_a?(Numeric) @interval = seconds @repeats = [:repeat] != false @_ = NSTimer.scheduledTimerWithTimeInterval @interval, target: self, selector: :kick, userInfo: nil, repeats: @repeats end |
Instance Attribute Details
#_ ⇒ Object (readonly)
Returns the value of attribute _.
12 13 14 |
# File 'lib/under_os/timer.rb', line 12 def _ @_ end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
12 13 14 |
# File 'lib/under_os/timer.rb', line 12 def block @block end |
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
12 13 14 |
# File 'lib/under_os/timer.rb', line 12 def counter @counter end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
12 13 14 |
# File 'lib/under_os/timer.rb', line 12 def interval @interval end |
#repeats ⇒ Object (readonly)
Returns the value of attribute repeats.
12 13 14 |
# File 'lib/under_os/timer.rb', line 12 def repeats @repeats end |
Class Method Details
Instance Method Details
#kick ⇒ Object
29 30 31 32 |
# File 'lib/under_os/timer.rb', line 29 def kick @block.call stop if @counter && (@counter -= 1) <= 0 end |
#stop ⇒ Object
24 25 26 27 |
# File 'lib/under_os/timer.rb', line 24 def stop @_.invalidate self end |