Skip to content

Commit

Permalink
rate error fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
hamitturkukaya committed Jun 1, 2013
1 parent e7ca118 commit d50738e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/money/bank/tcmb_currency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require "active_record"

class Money
def exchange_to(to_currency, date = Time.now.to_date)
def exchange_to(to_currency, date = nil)
other_currency = Currency.wrap(to_currency)
bank = Bank::TcmbCurrency.new
bank.exchange_with(self, to_currency, date)
Expand Down Expand Up @@ -68,8 +68,14 @@ def get_rate(from, to, date)

def fetch_rate(from, to, date)
from, to = Currency.wrap(from), Currency.wrap(to)
f = CrossRate.where(code: from.to_s, date: date).last
t = CrossRate.where(code: to.to_s, date: date).last
if date.nil?
f = CrossRate.where(code: from.to_s).last
t = CrossRate.where(code: to.to_s).last
else
f = CrossRate.where(code: from.to_s, date: date).last
t = CrossRate.where(code: to.to_s, date: date).last
end

return rate = t.rate.to_f/f.rate.to_f
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tcmb_currency/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TcmbCurrency
VERSION = "0.2.0"
VERSION = "0.3.0"
end

0 comments on commit d50738e

Please sign in to comment.