Class: Lariconv
- Inherits:
-
Object
- Object
- Lariconv
- Defined in:
- lib/lariconv.rb
Overview
TODO: Add info from TBC, Liberty, Basisbank, as well as from Wise Business and Revolut Business
Defined Under Namespace
Classes: InvalidAmountException, UnavailableCurrencyException
Class Method Summary collapse
Instance Method Summary collapse
- #amount ⇒ Object
-
#convert ⇒ BigDecimal
Converted amount of money.
- #currency ⇒ Object
- #date ⇒ Object
-
#initialize(amount:, currency:, date: nil) ⇒ Lariconv
constructor
A new instance of Lariconv.
Constructor Details
#initialize(amount:, currency:, date: nil) ⇒ Lariconv
Returns a new instance of Lariconv.
29 30 31 32 33 |
# File 'lib/lariconv.rb', line 29 def initialize(amount:, currency:, date: nil) @amount = amount @currency = currency.upcase @date = date end |
Class Method Details
.convert ⇒ Object
25 26 27 |
# File 'lib/lariconv.rb', line 25 def self.convert(...) new(...).convert end |
Instance Method Details
#amount ⇒ Object
45 46 47 48 49 |
# File 'lib/lariconv.rb', line 45 def amount raise InvalidAmountException unless [Integer, Float, BigDecimal].include? @amount.class @amount.to_d end |
#convert ⇒ BigDecimal
Returns Converted amount of money.
39 40 41 42 43 |
# File 'lib/lariconv.rb', line 39 def convert quantity, rate = fetch_currency_data result = (amount / quantity) * rate result.round(2) end |
#currency ⇒ Object
51 52 53 54 55 |
# File 'lib/lariconv.rb', line 51 def currency raise UnavailableCurrencyException unless CURRENCIES.include? @currency @currency end |
#date ⇒ Object
57 58 59 |
# File 'lib/lariconv.rb', line 57 def date @date ||= parse_date end |