Module: DwollaV2::Util

Defined in:
lib/dwolla_v2/util.rb

Class Method Summary collapse

Class Method Details

.classify(str) ⇒ Object



25
26
27
28
29
# File 'lib/dwolla_v2/util.rb', line 25

def self.classify str
  str.split("_").map do |i|
    i.sub(/^(.)/) { $1.capitalize }
  end.join
end

.deep_parse_iso8601_values(obj) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dwolla_v2/util.rb', line 13

def self.deep_parse_iso8601_values obj
  if obj.is_a? Hash
    Hash[obj.map{|k,v| [k, deep_parse_iso8601_values(v)] }]
  elsif obj.is_a? Array
    obj.map {|i| deep_parse_iso8601_values(i) }
  elsif obj.is_a? String
    Time.iso8601 obj rescue obj
  else
    obj
  end
end

.deep_super_hasherize(obj) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/dwolla_v2/util.rb', line 3

def self.deep_super_hasherize obj
  if obj.is_a? Hash
    SuperHash[obj.map{|k,v| [k, deep_super_hasherize(v)] }]
  elsif obj.is_a? Array
    obj.map {|i| deep_super_hasherize(i) }
  else
    obj
  end
end

.pretty_inspect(klass_name, attrs, append = nil) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/dwolla_v2/util.rb', line 31

def self.pretty_inspect klass_name, attrs, append = nil
  [
    "#<#{klass_name}",
    attrs.map {|k,v| " #{k}=#{v.inspect}" unless v.nil? },
    (" #{append.is_a?(String) ? append.inspect : append}" unless append.nil?),
    ">"
  ].flatten.join
end