Class: InvestecOpenApi::Models::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/investec_open_api/models/base.rb

Direct Known Subclasses

Account, Balance, Transaction

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
# File 'lib/investec_open_api/models/base.rb', line 7

def initialize(params)
  params
    .transform_keys(&:underscore)
    .each { |key, value| instance_variable_set("@#{key}", value) }
end

Class Method Details

.convert_param_value_to_date(params, key) ⇒ Object



33
34
35
# File 'lib/investec_open_api/models/base.rb', line 33

def self.convert_param_value_to_date(params, key)
  params[key] = Date.parse(params[key]) unless params[key].nil?
end

.convert_param_value_to_money(params, key, currency_key = "currency", should_make_negative = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/investec_open_api/models/base.rb', line 17

def self.convert_param_value_to_money(
  params,
  key,
  currency_key = "currency",
  should_make_negative = false
)
  if params[key].nil?
    return
  end
  value_in_cents = params[key] * 100
  value_in_cents = -value_in_cents if should_make_negative
  params[key] = Money.from_cents(
    value_in_cents,
    params[currency_key])
end

.rewrite_param_key(params, key, rewritten_key) ⇒ Object



13
14
15
# File 'lib/investec_open_api/models/base.rb', line 13

def self.rewrite_param_key(params, key, rewritten_key)
  params[rewritten_key] = params[key] unless params[key].nil?
end