Module: Growl

Defined in:
lib/growl/growl.rb,
lib/growl/version.rb

Defined Under Namespace

Classes: Base, Error

Constant Summary collapse

PACKAGED_BIN =
File.expand_path(File.dirname(__FILE__) + '/notify/growlnotify')
VERSION =
'1.0.5'

Class Method Summary collapse

Class Method Details

.exec(*args) ⇒ Object

Execute args against the binary.



59
60
61
62
63
64
# File 'lib/growl/growl.rb', line 59

def self.exec *args
  bin = PACKAGED_BIN
  bin += '.exe' if is_windows?

  Kernel.system bin, *args
end

.installed?Boolean

Check if the binary is installed and accessable.

Returns:

  • (Boolean)


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

def self.installed?
  version
end

.is_windows?Boolean

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/growl/growl.rb', line 51

def self.is_windows?
  processor, platform, *rest = RUBY_PLATFORM.split("-")
  platform == 'mswin32'
end

.new(*args, &block) ⇒ Object

Return an instance of Growl::Base or nil when not installed.



83
84
85
86
# File 'lib/growl/growl.rb', line 83

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



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/growl/growl.rb', line 99

def self.normalize_icon! options = {}
  return unless options.include? :icon
  icon = options.delete(:icon).to_s
  if File.exists? icon
    if File.extname(icon) == '.icns'
      options[:iconpath] = icon
    else
      options[:image] = icon
    end
  else
    if icon.capitalize == icon
      options[:appIcon] = icon
    elsif !(ext = File.extname(icon)).empty?
      options[:icon] = ext[1..-1]
    else
      options[: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.message = 'Hello'; n.sticky! }
Growl.notify { self.message = 'Hello'; sticky! }


30
31
32
33
34
35
# File 'lib/growl/growl.rb', line 30

def notify message = nil, options = {}, &block
  return unless Growl.installed?
  options.merge! :message => message if message
  Growl.normalize_icon! options
  Growl.new(options, &block).run
end

.versionObject

Return the version triple of the binary.



69
70
71
# File 'lib/growl/growl.rb', line 69

def self.version
  return '0.0.0'
end