Files
sure/app/models/exchange_rate.rb
2024-03-07 17:46:36 -05:00

15 lines
401 B
Ruby

class ExchangeRate < ApplicationRecord
def self.convert(from, to, amount)
return amount unless EXCHANGE_RATE_ENABLED
rate = ExchangeRate.find_by(base_currency: from, converted_currency: to)
# TODO: Handle the case where the rate is not found
if rate.nil?
amount # Silently handle the error by returning the original amount
else
amount * rate.rate
end
end
end