Class: GrowlNotify

Inherits:
Object
  • Object
show all
Extended by:
Appscript
Defined in:
lib/growl_notify.rb

Defined Under Namespace

Classes: GrowlNotFound

Constant Summary collapse

VERSION =
"0.0.3"
PRE_1_3_APP =
"GrowlHelperApp"
POST_1_3_APP =
"Growl"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.application_nameObject

Returns the value of attribute application_name.



11
12
13
# File 'lib/growl_notify.rb', line 11

def application_name
  @application_name
end

.default_notificationsObject

Returns the value of attribute default_notifications.



11
12
13
# File 'lib/growl_notify.rb', line 11

def default_notifications
  @default_notifications
end

.iconObject

Returns the value of attribute icon.



11
12
13
# File 'lib/growl_notify.rb', line 11

def icon
  @icon
end

.notificationsObject

Returns the value of attribute notifications.



11
12
13
# File 'lib/growl_notify.rb', line 11

def notifications
  @notifications
end

Class Method Details

.applicationObject

Raises:



32
33
34
35
36
37
# File 'lib/growl_notify.rb', line 32

def application
  @application = pre1_3_app
  @application ||= post1_3_app
  raise GrowlNotFound if @application.nil?
  @application
end

.config(&block) ⇒ Object



17
18
19
20
# File 'lib/growl_notify.rb', line 17

def config(&block)
  block.call(self)
  register
end

.emergency(options = {}) ⇒ Object



81
82
83
84
# File 'lib/growl_notify.rb', line 81

def emergency(options={})
  options.merge!(:priority => 2)
  send_notification(options)
end

.high(options = {}) ⇒ Object



76
77
78
79
# File 'lib/growl_notify.rb', line 76

def high(options={})
  options.merge!(:priority => 1)
  send_notification(options)
end

.moderate(options = {}) ⇒ Object



66
67
68
69
# File 'lib/growl_notify.rb', line 66

def moderate(options={})
  options.merge!(:priority => -1)
  send_notification(options)
end

.normal(options = {}) ⇒ Object



71
72
73
74
# File 'lib/growl_notify.rb', line 71

def normal(options={})
  options.merge!(:priority => 0)
  send_notification(options)      
end

.post1_3_appObject



45
46
47
48
49
# File 'lib/growl_notify.rb', line 45

def post1_3_app
  app(POST_1_3_APP)
rescue FindApp::ApplicationNotFoundError
  nil
end

.pre1_3_appObject



39
40
41
42
43
# File 'lib/growl_notify.rb', line 39

def pre1_3_app
  app(PRE_1_3_APP)
rescue FindApp::ApplicationNotFoundError
  nil
end

.registerObject



28
29
30
# File 'lib/growl_notify.rb', line 28

def register
  application.register(:all_notifications => @notifications, :as_application => @application_name, :default_notifications => @default_notifications)
end

.reset!Object



22
23
24
25
26
# File 'lib/growl_notify.rb', line 22

def reset!
  [:application_name, :default_notifications, :notifications, :icon].each do |meth|
    send(:"#{meth}=", nil)
  end
end

.send_notification(options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/growl_notify.rb', line 51

def send_notification(options= {})
  defaults = {:title => 'no title', :application_name => @application_name, :description => 'no description', :sticky => false, :priority => 0, :with_name => notifications.first}
  local_icon = @icon
  local_icon = options.delete(:icon) if options.include?(:icon)
  if local_icon
    defaults.merge!(:image_from_location => local_icon)
  end
  application.notify(defaults.merge(options))
end

.sticky!(options = {}) ⇒ Object



86
87
88
89
# File 'lib/growl_notify.rb', line 86

def sticky!(options={})
  options.merge!(:sticky => true)
  send_notification(options)
end

.very_low(options = {}) ⇒ Object



61
62
63
64
# File 'lib/growl_notify.rb', line 61

def very_low(options={})
  options.merge!(:priority => -2)
  send_notification(options)
end