Class: Growl::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/growl/growl.rb

Overview

– Growl base ++

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Base

Initialize with optional block, which is then instance evaled or yielded depending on the blocks arity.



130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/growl/growl.rb', line 130

def initialize options = {}, &block
  @args = []
  if block_given?
    if block.arity > 0
      yield self
    else
      self.instance_eval &block
    end
  else
    options.each do |key, value|
      send :"#{key}=", value
    end
  end
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



124
125
126
# File 'lib/growl/growl.rb', line 124

def args
  @args
end

Class Method Details

.switch(name, win_name) ⇒ Object

Define a switch name.

examples

switch :sticky

@growl.sticky!         # => true
@growl.sticky?         # => true
@growl.sticky = false  # => false
@growl.sticky?         # => false


185
186
187
188
189
190
191
# File 'lib/growl/growl.rb', line 185

def self.switch name, win_name
  ivar = :"@#{name}"
  (@switches ||= []) << [name, win_name]
  attr_accessor :"#{name}"
  define_method(:"#{name}?") { instance_variable_get(ivar) }
  define_method(:"#{name}!") { instance_variable_set(ivar, true) }
end

.switchesObject

Return array of available switch symbols.



196
197
198
# File 'lib/growl/growl.rb', line 196

def self.switches
  @switches
end

Instance Method Details

#is_windows?Boolean

Returns:

  • (Boolean)


145
146
147
148
# File 'lib/growl/growl.rb', line 145

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

#runObject

Run the notification, only –message is required.

Raises:



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/growl/growl.rb', line 153

def run
  raise Error, 'message required' unless message
  self.class.switches.each do |name, win_name|
    if send(:"#{name}?")
      value = send(name).to_s if send(name) && !(TrueClass === send(name))
      if is_windows?
        next if win_name.nil?
        
        arg = is_windows? ? ( (win_name == :EMPTY) ? "" : "/#{win_name}:") : "--#{name}"
        args << arg + value
      else
        args << "--#{name}"
        args << value
      end
    end
  end
  Growl.exec *args
end