Class: Notify
- Inherits:
-
Object
- Object
- Notify
- Defined in:
- lib/Notify.rb
Constant Summary collapse
- SupportedMethods =
%w{notify-send growlnotify awesome-client}- Icon =
File.dirname(__FILE__) + "/../share/icon.png"
Instance Method Summary collapse
- #getBinary(name) ⇒ Object
-
#initialize(notifyMethod) ⇒ Notify
constructor
A new instance of Notify.
- #notify(message) ⇒ Object
Constructor Details
#initialize(notifyMethod) ⇒ Notify
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/Notify.rb', line 6 def initialize(notifyMethod) @method = nil case notifyMethod when nil #do nothing when "none" #do nothing when "auto" #auto detect notifier lib SupportedMethods.each do |method| @binary = getBinary(method) unless @binary.nil? @method = method break end end else #use specified binary unless SupportedMethods.include? notifyMethod raise ArgumentError, "Notification method #{notifyMethod} is not supported" end @binary = getBinary(notifyMethod) @method = notifyMethod raise ArgumentError, "No binary found for #{notifyMethod} in PATH" if @binary.nil? end end |
Instance Method Details
#getBinary(name) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/Notify.rb', line 34 def getBinary(name) binary = `which #{name}`.chomp if $?.success? binary else nil end end |
#notify(message) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/Notify.rb', line 43 def notify() case @method when nil #great, do nothing when "notify-send" system("notify-send --icon #{Icon} --urgency critical Subcl '#{message}'") when "growlnotify" system("growlnotify --image #{Icon} --title Subcl --message '#{message}'") when "awesome-client" naughtyCmd = %Q{ naughty.notify({ title='subcl', text='#{message}', icon='#{Icon}', timeout = 10 }) } naughtyCmd.gsub! "\n" " " system(%Q{echo "#{naughtyCmd}" | awesome-client}) end end |