Class: Hyperwallet::Response::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hyperwallet/response/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Base

Returns a new instance of Base.



10
11
12
# File 'lib/hyperwallet/response/base.rb', line 10

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/hyperwallet/response/base.rb', line 4

def data
  @data
end

Class Method Details

.format(data) ⇒ Object



6
7
8
# File 'lib/hyperwallet/response/base.rb', line 6

def self.format(data)
  new(data).format
end

Instance Method Details

#formatObject



14
15
16
17
18
19
20
# File 'lib/hyperwallet/response/base.rb', line 14

def format
  if data.is_a?(Array)
    data.map { |item| format_single(item) }
  else
    format_single(data)
  end
end

#to_h(dict, data) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/hyperwallet/response/base.rb', line 22

def to_h(dict, data)
  return {} if data.nil?

  dict.each_with_object({}) do |(l, r), object|
    object[l] = data[r]
  end
end