Class: Weechat::Timer
Instance Attribute Summary collapse
-
#align ⇒ Object
readonly
Returns the value of attribute align.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
Attributes inherited from Hook
Attributes included from Pointer
Instance Method Summary collapse
- #_init(interval, align, max) ⇒ Object
- #call(remaining) ⇒ Object
-
#initialize(interval, max = 0, align = 0, &block) ⇒ Timer
constructor
A new instance of Timer.
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Methods inherited from Hook
compute_free_id, find_by_id, #hooked?, hooks, inherited, init, register, #unhook, unhook, unhook_all, unregister
Methods included from Pointer
Constructor Details
#initialize(interval, max = 0, align = 0, &block) ⇒ Timer
Returns a new instance of Timer.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/weechat/timer.rb', line 6 def initialize(interval, max=0, align=0, &block) super @remaining= nil @callback = EvaluatedCallback.new(block) @interval = interval @align = align @max = max @ptr = _init(interval, align, max) self.class.register(self) end |
Instance Attribute Details
#align ⇒ Object (readonly)
Returns the value of attribute align.
4 5 6 |
# File 'lib/weechat/timer.rb', line 4 def align @align end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
3 4 5 |
# File 'lib/weechat/timer.rb', line 3 def interval @interval end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
5 6 7 |
# File 'lib/weechat/timer.rb', line 5 def max @max end |
Instance Method Details
#_init(interval, align, max) ⇒ Object
17 18 19 |
# File 'lib/weechat/timer.rb', line 17 def _init(interval, align, max) Weechat.hook_timer(interval, align, max, "timer_callback", @id.to_s) end |
#call(remaining) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/weechat/timer.rb', line 21 def call(remaining) @remaining = remaining.to_i ret = super if @remaining == 0 self.unhook end return ret end |
#restart ⇒ Object
50 51 52 53 54 |
# File 'lib/weechat/timer.rb', line 50 def restart stop @remaining = nil start end |
#start ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/weechat/timer.rb', line 36 def start unless @hooked if @remaining == 0 || @remaining.nil? # the timer never ran or finished already. restart it max = @max else # continue running hook max = @remaining end @ptr = _init(@interval, @align, max) end end |
#stop ⇒ Object
32 33 34 |
# File 'lib/weechat/timer.rb', line 32 def stop unhook end |