Class: Growl::Base
- Inherits:
-
Object
- Object
- Growl::Base
- Defined in:
- lib/growl/growl.rb
Overview
– Growl base ++
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Class Method Summary collapse
-
.switch(name, win_name) ⇒ Object
Define a switch
name. -
.switches ⇒ Object
Return array of available switch symbols.
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ Base
constructor
Initialize with optional
block, which is then instance evaled or yielded depending on the blocks arity. - #is_windows? ⇒ Boolean
-
#run ⇒ Object
Run the notification, only –message is required.
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 = {}, &block @args = [] if block_given? if block.arity > 0 yield self else self.instance_eval &block end else .each do |key, value| send :"#{key}=", value end end end |
Instance Attribute Details
#args ⇒ Object (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 |
.switches ⇒ Object
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
145 146 147 148 |
# File 'lib/growl/growl.rb', line 145 def is_windows? processor, platform, *rest = RUBY_PLATFORM.split("-") platform == 'mswin32' end |
#run ⇒ Object
Run the notification, only –message is required.
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 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? switch = (win_name == :EMPTY) ? "" : "/#{win_name}:" args << switch + value else args << "--#{name}" args << value end end end Growl.exec *args end |