class RailsCurrency::Convertor
Constants
- PARAMS
Public Class Methods
conversion_service(service_name)
click to toggle source
# File lib/rails_currency/convertor.rb, line 53 def conversion_service(service_name) service_name.downcase == 'xe' ? Convertor::Xe : Convertor::Google end
convert(amount, from, to, service = 'google')
click to toggle source
# File lib/rails_currency/convertor.rb, line 31 def convert(amount, from, to, service = 'google') raise InvalidAmountError, 'Only numeric value allowed' unless amount.is_a?(Numeric) unless conversion_service(service)::CURRENCIES.key?(from) && conversion_service(service)::CURRENCIES.key?(to) raise UnknownCurrencyError, 'Unknown Currency' end begin timeout(30) do conversion_service(service).process_request(amount, from, to) end rescue TimeoutError raise ServerTimeoutError, "Can't connect to server #{service_url(service)}" end end
get_rate(from, to, service = 'google')
click to toggle source
# File lib/rails_currency/convertor.rb, line 49 def get_rate(from, to, service = 'google') conversion_service(service).get_rate(from, to) end
service_url(service)
click to toggle source
# File lib/rails_currency/convertor.rb, line 45 def service_url(service) conversion_service(service).service_url end