module Arbolito
Constants
- VERSION
Public Class Methods
add_currency_rate(currency_price, from_to_currencies)
click to toggle source
# File lib/arbolito.rb, line 14 def add_currency_rate(currency_price, from_to_currencies) rate = Currency::NonExpirableRate.new(currency_price, from_to_currencies) add_to_store(rate) end
convert(money, from_to_currencies)
click to toggle source
# File lib/arbolito.rb, line 23 def convert(money, from_to_currencies) quote = Currency::Quote.new(from_to_currencies) rate = fetch(quote) rate.convert(money) end
current_rate(from_to_currencies)
click to toggle source
# File lib/arbolito.rb, line 19 def current_rate(from_to_currencies) fetch(Currency::Quote.new(from_to_currencies)).price end
set(config_key, value)
click to toggle source
# File lib/arbolito.rb, line 35 def set(config_key, value) settings[config_key] = value end
settings()
click to toggle source
# File lib/arbolito.rb, line 31 def settings @settings ||= {} end
Private Class Methods
add_to_store(rate)
click to toggle source
# File lib/arbolito.rb, line 40 def add_to_store(rate) store.add(rate) store.add(rate.backwards) end
exchange()
click to toggle source
# File lib/arbolito.rb, line 61 def exchange settings[:exchange] ||= Exchange::YahooFinance end
expiration_time()
click to toggle source
# File lib/arbolito.rb, line 65 def expiration_time settings[:expiration_time] ||= 60 end
fetch(quote)
click to toggle source
# File lib/arbolito.rb, line 45 def fetch(quote) rate = store.fetch(quote) if(!rate || rate.expired?(expiration_time)) rate = exchange.find_current_rate(quote) store.add(rate) end rate end
store()
click to toggle source
# File lib/arbolito.rb, line 57 def store settings[:store] ||= Store::Memory end