Class: GrowlNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/notifiers/growl_notifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ GrowlNotifier

Returns a new instance of GrowlNotifier.



9
10
11
12
13
14
# File 'lib/notifiers/growl_notifier.rb', line 9

def initialize(opts = {})
  @server = opts['server'] || '127.0.0.1'
  @sticky = opts['sticky'] || false
  @use_growl_gem = opts['use_growl_gem'] == false ? false : true 
  @output_lines = opts['output_lines'] || 2
end

Instance Method Details

#notify(message, title = '', data = []) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/notifiers/growl_notifier.rb', line 16

def notify(message, title = '', data = [])
  msg = message.dup
  if data.any?
    msg << "\n\n" 
    #msg <<  "......#{data.length - @output_lines} more lines\n"  
    #(@output_lines - 1).downto(0).each{|i| msg << "#{data.length - i}: #{data[i]}"}
    data.last(@output_lines).each_with_index{|line,i| msg << "#{data.length - i}: #{line}"}
    msg <<  "......#{data.length - @output_lines} more lines"  
  end
  (@use_growl_gem && GROWL_GEM) ? notify_via_gem(msg, title) : notify_via_binary(msg, title)
end