Module: GoobyEnvironment

Included in:
GoobyBaseObject, GoobyProcess
Defined in:
lib/gooby_environment.rb

Overview

Gooby = Google APIs + Ruby. Copyright 2009 by Chris Joakim. Gooby is available under GNU General Public License (GPL) license.

Instance Method Summary collapse

Instance Method Details

#array_param(name, default = []) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gooby_environment.rb', line 35

def array_param(name, default=[])
  array = []    
  csv_value = string_param(name.to_s, nil)
  if csv_value
    FasterCSV.parse(csv_value) do | row |
      row.each { | value | array << value }
    end
    array
  else
    default
  end
end

#boolean_param(name, default = false) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/gooby_environment.rb', line 15

def boolean_param(name, default=false)
  value = ENV[name.to_s]
  return default if value.nil?
  return true  if (value.downcase == 'true')  || (value.downcase == 't')
  return false if (value.downcase == 'false') || (value.downcase == 'f')
  default  
end

#command_line_arg(arg_name, default_value = nil) ⇒ Object



10
11
12
13
# File 'lib/gooby_environment.rb', line 10

def command_line_arg(arg_name, default_value=nil)
  value = ENV[arg_name]  
  (value.nil?) ? default_value : value
end

#float_param(name, default = 0.0) ⇒ Object



27
28
29
# File 'lib/gooby_environment.rb', line 27

def float_param(name, default=0.0)
  (ENV[name.to_s]) ? ENV[name.to_s].to_f : default.to_f
end

#integer_param(name, default = 0) ⇒ Object



23
24
25
# File 'lib/gooby_environment.rb', line 23

def integer_param(name, default=0)
  (ENV[name.to_s]) ? ENV[name.to_s].to_i : default.to_i
end

#string_param(name, default = '') ⇒ Object



31
32
33
# File 'lib/gooby_environment.rb', line 31

def string_param(name, default='')
  (ENV[name.to_s]) ? ENV[name.to_s] : default.to_s
end