Module: AdyenClient::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/adyen_client/utils.rb

Instance Method Summary collapse

Instance Method Details

#massage_response(value, parent = nil) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/adyen_client/utils.rb', line 2

def massage_response(value, parent = nil)
  case value
  when Array
    value.map { |v| massage_response(v, value) }
  when Hash
    if parent.is_a?(Array) && value.count == 1
      _, v = value.first
      massage_response(v, value)
    else
      Hash[value.map { |k, v| [snake_caseify(k), massage_response(v, value)] }]
    end
  else
    value
  end
end

#snake_caseify(string) ⇒ Object


18
19
20
21
22
23
24
25
# File 'lib/adyen_client/utils.rb', line 18

def snake_caseify(string)
  string
    .gsub("::", "/")
    .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .tr("-", "_")
    .downcase
end