class CurrencyExchange::Rate
Constants
- DATE_FORMAT
Attributes
ask[RW]
bid[RW]
name[RW]
rate[RW]
time[RW]
Public Class Methods
new(name, rate, options = {})
click to toggle source
# File lib/currency_exchange/rate.rb, line 6 def initialize(name, rate, options = {}) @name = name @rate = rate.to_f @time = parse_date options[:date], options[:time] @ask = options[:ask].to_f @bid = options[:bid].to_f end
rate_for(currency1, currency2)
click to toggle source
# File lib/currency_exchange/rate.rb, line 18 def self.rate_for(currency1, currency2) CurrencyExchange::Yahoo.get_rates [[currency1, currency2]] end
Public Instance Methods
convert_value(value)
click to toggle source
# File lib/currency_exchange/rate.rb, line 14 def convert_value(value) rate * value end
Private Instance Methods
parse_date(date, time)
click to toggle source
# File lib/currency_exchange/rate.rb, line 24 def parse_date(date, time) parse_date_format(date, time) || parse_date_no_format(date) || Time.now end
parse_date_format(date, time)
click to toggle source
# File lib/currency_exchange/rate.rb, line 28 def parse_date_format(date, time) Time.strptime "#{date} #{time}", DATE_FORMAT rescue ArgumentError end
parse_date_no_format(date)
click to toggle source
# File lib/currency_exchange/rate.rb, line 33 def parse_date_no_format(date) Time.parse date rescue ArgumentError, TypeError end