class BitConverter::Convert
Public Class Methods
convert(amount:, from:, to:)
click to toggle source
# File lib/bit_converter/convert.rb, line 8 def convert(amount:, from:, to:) rate_of(to.upcase) / rate_of(from.upcase) * amount end
pretty_convert(amount:, from:, to:)
click to toggle source
# File lib/bit_converter/convert.rb, line 12 def pretty_convert(amount:, from:, to:) result = convert(amount: amount, from: from, to: to) helper.number_to_currency(result, unit: "") end
Private Class Methods
helper()
click to toggle source
# File lib/bit_converter/convert.rb, line 20 def helper @helper ||= Class.new do include ActionView::Helpers::NumberHelper end.new end
rate_of(currency)
click to toggle source
# File lib/bit_converter/convert.rb, line 26 def rate_of(currency) raise "Currencies #{currency} unavailable" if rates[currency].nil? rates[currency].to_f end
rates()
click to toggle source
# File lib/bit_converter/convert.rb, line 32 def rates @rates ||= CoinbaseWrapper.usd_exchange_rates end