Class: Ircbot::Utils::Watcher
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Watcher
constructor
A new instance of Watcher.
- #process(src) ⇒ Object
- #run ⇒ Object
- #srcs ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Watcher
Returns a new instance of Watcher.
7 8 9 10 |
# File 'lib/ircbot/utils/watcher.rb', line 7 def initialize( = {}) interval [:interval] || self.class.interval callback [:callback] || self.class.callback end |
Instance Method Details
#process(src) ⇒ Object
16 17 18 |
# File 'lib/ircbot/utils/watcher.rb', line 16 def process(src) return true end |
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ircbot/utils/watcher.rb', line 20 def run loop do srcs.each do |src| if process(src) callback.call(src) end end sleep interval end end |
#srcs ⇒ Object
12 13 14 |
# File 'lib/ircbot/utils/watcher.rb', line 12 def srcs return [] end |
#start ⇒ Object
31 32 33 |
# File 'lib/ircbot/utils/watcher.rb', line 31 def start Thread.new{ run } end |