Class: Lumione::Bank

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::DateHelper
Defined in:
lib/lumione/bank.rb

Constant Summary collapse

DEFAULT_CACHE_DIR =
File.join(Dir.home, ".cache", "lumione")
CACHE_DIR =
ENV["LUMIONE_CACHE_DIR"] || DEFAULT_CACHE_DIR
CACHE_FILE =
File.join(CACHE_DIR, "exchange_rates.xml")

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert_and_print(amount, from_currency, to_currency) ⇒ Object



13
14
15
# File 'lib/lumione/bank.rb', line 13

def self.convert_and_print(amount, from_currency, to_currency)
  new.convert_and_print amount, from_currency, to_currency
end

Instance Method Details

#convert(amount, from_currency, to_currency) ⇒ Object



33
34
35
36
# File 'lib/lumione/bank.rb', line 33

def convert(amount, from_currency, to_currency)
  @original_money = Money.from_amount(amount, from_currency)
  @converted_money = @original_money.exchange_to(to_currency)
end

#convert_and_print(amount, from_currency, to_currency) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/lumione/bank.rb', line 17

def convert_and_print(amount, from_currency, to_currency)
  prepare_rates

  convert(amount, from_currency, to_currency)

  print_original_and_converted_money
end

#prepare_ratesObject



38
39
40
41
# File 'lib/lumione/bank.rb', line 38

def prepare_rates
  create_cache_dir
  update_and_load_rates
end


25
26
27
28
29
30
31
# File 'lib/lumione/bank.rb', line 25

def print_original_and_converted_money
  print format_conversion(@original_money, @converted_money)
  if bank.rates_updated_at < 2.days.ago
    print " (#{how_long_since_rates_were_updated(bank.rates_updated_at)})"
  end
  puts
end