Class: Kodiak::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/kodiak/notification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, type = "message") ⇒ Notification

Returns a new instance of Notification.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kodiak/notification.rb', line 10

def initialize(message, type = "message")
    @message = message
    @type = type
	
	console_notify
	
	if Config::CONFIG['target_os'] =~ /darwin/i
		@growl = Appscript.app("GrowlHelperApp");
	
		if @growl.is_running?
			growl_register
			growl_notify
		end
	end
end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



8
9
10
# File 'lib/kodiak/notification.rb', line 8

def application
  @application
end

#default_notificationsObject

Returns the value of attribute default_notifications.



8
9
10
# File 'lib/kodiak/notification.rb', line 8

def default_notifications
  @default_notifications
end

#growlObject

Returns the value of attribute growl.



8
9
10
# File 'lib/kodiak/notification.rb', line 8

def growl
  @growl
end

#iconObject

Returns the value of attribute icon.



8
9
10
# File 'lib/kodiak/notification.rb', line 8

def icon
  @icon
end

#messageObject

Returns the value of attribute message.



8
9
10
# File 'lib/kodiak/notification.rb', line 8

def message
  @message
end

#notificationsObject

Returns the value of attribute notifications.



8
9
10
# File 'lib/kodiak/notification.rb', line 8

def notifications
  @notifications
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/kodiak/notification.rb', line 8

def type
  @type
end

Instance Method Details

#console_notifyObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kodiak/notification.rb', line 27

def console_notify
	case @type
	when "success"
    print @message.green
	when "warning"
    print @message.yellow
  when "failure"
    print @message.red
	else
    print @message.white
	end
end

#growl_notifyObject

trigger a growl notification



42
43
44
45
46
47
48
49
50
51
# File 'lib/kodiak/notification.rb', line 42

def growl_notify
	options = { :title => @application,
							:description => @message.gsub(/[\n]+/, ""),
							:application_name => @application,
							:image_from_location => @icon,
							:sticky => false,
							:priority => 0,
							:with_name => notifications.first }
    @growl.notify options			
end

#growl_registerObject

register Kodiak as an application with Growl



55
56
57
58
59
60
61
# File 'lib/kodiak/notification.rb', line 55

def growl_register
			@application = Kodiak::APP_NAME
			@icon = "#{Kodiak::CONFIG_PATH}/#{Kodiak::CONFIG_ICON}"
 @default_notifications = ["Kodiak Success"]
 @notifications = ["Kodiak Success", "Kodiak Failure"]
  @growl.register(:as_application => @application, :all_notifications => @notifications, :default_notifications => @default_notifications)
end