Class: Smith::Budget::AmountRepresentation

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/smith/budget/amount_representation.rb

Instance Method Summary collapse

Instance Method Details

#externalize(amounts) ⇒ Object



17
18
19
# File 'lib/smith/budget/amount_representation.rb', line 17

def externalize(amounts)
  amounts.to_h { |key, amount| [key, externalize_amount(key, amount)] }
end

#externalize_amount(key, amount) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/smith/budget/amount_representation.rb', line 21

def externalize_amount(key, amount)
  return finite_float!(amount) if limits.fetch(key).is_a?(Float)
  return amount if amount.is_a?(Integer)
  return amount.to_i if amount.frac.zero?

  finite_float!(amount)
end

#internalize(amounts) ⇒ Object



13
14
15
# File 'lib/smith/budget/amount_representation.rb', line 13

def internalize(amounts)
  amounts.to_h { |key, amount| [key, internalize_amount(amount)] }
end