Class: Cinch::Plugins::LogSearch
- Inherits:
-
Object
- Object
- Cinch::Plugins::LogSearch
- Includes:
- Cinch::Plugin
- Defined in:
- lib/cinch/plugins/logsearch/version.rb,
lib/cinch/plugins/logsearch/logsearch.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Method Summary collapse
- #execute(m, search) ⇒ Object
-
#initialize(*args) ⇒ LogSearch
constructor
A new instance of LogSearch.
Constructor Details
#initialize(*args) ⇒ LogSearch
Returns a new instance of LogSearch.
11 12 13 14 15 |
# File 'lib/cinch/plugins/logsearch/logsearch.rb', line 11 def initialize(*args) super @max_results = config[:max_results] || 5 @log_directory = config[:logs_directory] || File.join('.', 'logs', '*.log') end |
Instance Method Details
#execute(m, search) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cinch/plugins/logsearch/logsearch.rb', line 17 def execute(m, search) return unless log_files_exist? matches = search_for(search) if matches.empty? m.user.msg "No matches found!" else msg = ['Found', matches.count, 'matches before giving up,', 'here\'s the most recent', @max_results] m.user.msg msg.join(' ') matches.reverse[0..(@max_results - 1)].reverse.each do |match| m.user.msg match end end end |