class MCLib::Watcher
Attributes
watch_thread[RW]
Public Class Methods
new(mc_dir = nil)
click to toggle source
# File lib/mclib/watcher.rb, line 12 def initialize(mc_dir = nil) if mc_dir.nil? mc_dir = MCLib::get_mc_dir end @log_file = mc_dir + '/logs/latest.log' @log_watcher = FileWatch::Tail.new @parser = MCLib::LogParser.new end
Public Instance Methods
start()
click to toggle source
# File lib/mclib/watcher.rb, line 22 def start @watch_thread = Thread.new do @log_watcher.tail @log_file @log_watcher.subscribe do |path, line| if !line.empty? && !line.nil? event = @parser.parse line # fire the event with the correct event handler api parameters delegate_parameters event # always fire the :all handlers fire :all, event end end end end
stop()
click to toggle source
# File lib/mclib/watcher.rb, line 39 def stop @watch_thread.kill end
Private Instance Methods
delegate_parameters(event)
click to toggle source
# File lib/mclib/watcher.rb, line 45 def delegate_parameters(event) type = event.class.name.split('::').last.downcase.to_sym case type when :chat fire :chat, event.username, event.text when :login fire :login, event when :warning fire :warning, event.text end end