Module: Kvetch

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

Constant Summary collapse

VERSION =
"1.0.3"

Class Method Summary collapse

Class Method Details

.silence!Object

Silence methods



34
# File 'lib/kvetch.rb', line 34

def self.silence!() @silenced = true end

.silent?Boolean

Returns:

  • (Boolean)


36
# File 'lib/kvetch.rb', line 36

def self.silent?() @silenced end

.unsilence!Object



35
# File 'lib/kvetch.rb', line 35

def self.unsilence!() @silenced = false end

.yell(message, options = {}) ⇒ Object

Main usage: Kvetch.yell(MESSAGE)



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
# File 'lib/kvetch.rb', line 7

def self.yell(message, options = {})
  return false if @silenced

  if message.is_a? String
    if OS.mac? && `sw_vers -productVersion` >= '10.8'
      bin = File.expand_path('../../vendor/terminal-notifier/kvetch.app/Contents/MacOS/terminal-notifier', __FILE__)
      
      options[:sound].capitalize! if options[:sound]
      options = options.merge(:message => message).map do |argument, value|
        value = value.to_s; ["-#{argument}", "#{Shellwords.escape(value[0,1])}#{value[1..-1]}"]
      end

      command = [bin, *options.flatten]
      command = Shellwords.join(command) if RUBY_VERSION < '1.9'

      IO.popen(command) # send message and options to terminal-notifier/kvetch.app
    elsif OS.linux? || OS.unix?
      `notify-send \"#{message}\"`
    else # OS doesn't have notification support
      return "Kvetch works on Linux, Unix, or Mac OS X >= 10.8."
    end
  else # message is not a string
    return "You should give that kvetch a string. Kvetches love strings."
  end
end