Class: Ircbot::Utils::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ircbot/utils/watcher.rb

Instance Method Summary collapse

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(options = {})
  interval options[:interval] || self.class.interval
  callback options[: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

#runObject



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

#srcsObject



12
13
14
# File 'lib/ircbot/utils/watcher.rb', line 12

def srcs
  return []
end

#startObject



31
32
33
# File 'lib/ircbot/utils/watcher.rb', line 31

def start
  Thread.new{ run }
end