Class: Notify
- Inherits:
-
Object
- Object
- Notify
- Defined in:
- lib/subcl/notify.rb
Constant Summary collapse
- SupportedMethods =
%w{notify-send growlnotify awesome-client}
- Icon =
File.dirname(__FILE__) + "/../../share/icon.png"
Instance Method Summary collapse
- #get_binary(name) ⇒ Object
-
#initialize(notifyMethod) ⇒ Notify
constructor
A new instance of Notify.
- #notify(message) ⇒ Object
Constructor Details
#initialize(notifyMethod) ⇒ Notify
Returns a new instance of 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/subcl/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 = get_binary(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 = get_binary(notifyMethod) @method = notifyMethod raise ArgumentError, "No binary found for #{notifyMethod} in PATH" if @binary.nil? end end |
Instance Method Details
#get_binary(name) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/subcl/notify.rb', line 34 def get_binary(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/subcl/notify.rb', line 43 def notify() case @method when nil #great, do nothing when "notify-send" system("notify-send --icon #{Icon} --urgency critical Subcl '#{}'") when "growlnotify" system("growlnotify --image #{Icon} --title Subcl --message '#{}'") when "awesome-client" naughtyCmd = %Q{ naughty.notify({ title='subcl', text='#{}', icon='#{Icon}', timeout = 10 }) } naughtyCmd.gsub! "\n" " " system(%Q{echo "#{naughtyCmd}" | awesome-client}) end end |