Module: AlipayMini::Utils

Defined in:
lib/alipay_mini/utils.rb

Class Method Summary collapse

Class Method Details

.deep_compact(hash) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/alipay_mini/utils.rb', line 18

def self.deep_compact(hash)
  return hash unless hash.is_a?(::Hash)

  hash.each_with_object({}) do |(k, v), compact_hash|
    if v.is_a?(::Hash)
      compact_hash[k] = deep_compact(v)
    else
      compact_hash[k] = v unless v.nil?
    end
  end
end

.params_to_string(params) ⇒ Object



14
15
16
# File 'lib/alipay_mini/utils.rb', line 14

def self.params_to_string(params)
  params.sort.map{ |item| item.join('=') }.join('&')
end

.stringify_keys(hash) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/alipay_mini/utils.rb', line 4

def self.stringify_keys(hash)
  if hash.is_a? ::Hash
    return hash.inject({}) do |memo, (k, v)|
      memo.tap { |m| m[k.to_s] = self.stringify_keys(v) }
    end
  end

  hash
end