Module: Growl
- Defined in:
- lib/growl/growl.rb,
lib/growl/version.rb
Defined Under Namespace
Constant Summary collapse
- BIN =
'growlnotify'
- VERSION =
'1.0.3'
Class Method Summary collapse
-
.exec(*args) ⇒ Object
Execute
args
against the binary. -
.installed? ⇒ Boolean
Check if the binary is installed and accessable.
-
.new(*args, &block) ⇒ Object
Return an instance of Growl::Base or nil when not installed.
-
.normalize_icon!(options = {}) ⇒ Object
Normalize the icon option in
options
. -
.notify(message = nil, options = {}, &block) ⇒ Object
Display a growl notification
message
, withoptions
documented below. -
.version ⇒ Object
Return the version triple of the binary.
Class Method Details
.exec(*args) ⇒ Object
Execute args
against the binary.
54 55 56 |
# File 'lib/growl/growl.rb', line 54 def self.exec *args Kernel.system BIN, *args end |
.installed? ⇒ Boolean
Check if the binary is installed and accessable.
68 69 70 |
# File 'lib/growl/growl.rb', line 68 def self.installed? version rescue false end |
.new(*args, &block) ⇒ Object
Return an instance of Growl::Base or nil when not installed.
75 76 77 78 |
# File 'lib/growl/growl.rb', line 75 def self.new *args, &block return unless installed? Base.new *args, &block end |
.normalize_icon!(options = {}) ⇒ Object
Normalize the icon option in options
. This performs the following operations in order to allow for the :icon key to work with a variety of values:
-
path to an icon sets :iconpath
-
path to an image sets :image
-
capitalized word sets :appIcon
-
filename uses extname as :icon
-
otherwise treated as :icon
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/growl/growl.rb', line 91 def self.normalize_icon! = {} return unless .include? :icon icon = .delete(:icon).to_s if File.exists? icon if File.extname(icon) == '.icns' [:iconpath] = icon else [:image] = icon end else if icon.capitalize == icon [:appIcon] = icon elsif !(ext = File.extname(icon)).empty? [:icon] = ext[1..-1] else [:icon] = icon end end end |
.notify(message = nil, options = {}, &block) ⇒ Object
Display a growl notification message
, with options
documented below. Alternatively a block
may be passed which is then instance evaluated or yielded to the block.
This method is simply returns nil when growlnotify is not installed, as growl notifications should never be the only means of communication between your application and your user.
Examples
Growl.notify 'Hello'
Growl.notify 'Hello', :title => 'TJ Says:', :sticky => true
Growl.notify { |n| n. = 'Hello'; n.sticky! }
Growl.notify { self. = 'Hello'; sticky! }
30 31 32 33 34 35 |
# File 'lib/growl/growl.rb', line 30 def notify = nil, = {}, &block return unless Growl.installed? .merge! :message => if Growl.normalize_icon! Growl.new(, &block).run end |
.version ⇒ Object
Return the version triple of the binary.
61 62 63 |
# File 'lib/growl/growl.rb', line 61 def self.version @version ||= `#{BIN} --version`.split[1] end |