Method: PoolParty::Resource#print_variable

Defined in:
lib/poolparty/resource.rb

HELPERS FOR RESOURCES Print objects This helper takes an object and prints them out with as expected Case of:

Number:
  Integer of the format \d\d\d      => 0644
  Else                              => 79
String
  String of the format \d\d\d\d     => 0655
  String of the format \d\d\d       => 0644
  Else                              => "String"
Proc object
  Calls the proc object
Array
  All                               => [ "a", "b" ]
Symbol
  All                               => :a
Hash
  All                               => :a => "a", :b => ["b"]
Object
  All                               => object


255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/poolparty/resource.rb', line 255

def print_variable(obj)
  case obj
  when Fixnum
    case obj
    when /^\d{3}$/
      "0#{obj.to_i}"
    else
      "#{obj.to_i}"
    end        
  when String
    "\"#{obj}\""
  when Proc
    obj.call # eh
  when Array
    "[ #{obj.map {|e| print_variable(e) }.reject {|a| a.nil? || a.empty? }.join(", ")} ]"
  when nil
    nil
  when Symbol
    ":#{obj}"
  when Hash
    "#{obj.map {|k,v| ":#{k} => #{print_variable(v)}" unless v == obj }.compact.join(",\n")}"
  else
    "#{obj}"
  end
end