Class: SpotRate
- Inherits:
-
Object
show all
- Defined in:
- lib/spot-rate.rb,
lib/spot_rate/version.rb,
lib/spot_rate/google_currency_converter.rb
Defined Under Namespace
Classes: CurrencyNotFound, GoogleCurrencyConverter
Constant Summary
collapse
- VERSION =
"0.5.0"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config = {}) ⇒ SpotRate
Returns a new instance of SpotRate.
24
25
26
27
|
# File 'lib/spot-rate.rb', line 24
def initialize(config = {})
@from_currency = config[:from_currency]
@to_currency = config[:to_currency]
end
|
Instance Attribute Details
#from_currency ⇒ Object
Returns the value of attribute from_currency.
6
7
8
|
# File 'lib/spot-rate.rb', line 6
def from_currency
@from_currency
end
|
#to_currency ⇒ Object
Returns the value of attribute to_currency.
6
7
8
|
# File 'lib/spot-rate.rb', line 6
def to_currency
@to_currency
end
|
Class Method Details
.[](hash) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/spot-rate.rb', line 16
def self.[](hash)
raise ArgumentError unless hash.size <= 2
new(from_currency: hash.keys.first, to_currency: hash.values.first)
.use(hash[:use] || hash[:using] || :default)
.spot_rate
end
|
.available_converters ⇒ Object
8
9
10
|
# File 'lib/spot-rate.rb', line 8
def self.available_converters
@@available_converters ||= {}
end
|
.register_currency_converter(converter_key, converter_class) ⇒ Object
12
13
14
|
# File 'lib/spot-rate.rb', line 12
def self.register_currency_converter converter_key, converter_class
self.available_converters[converter_key.to_sym] = converter_class
end
|
Instance Method Details
#default_currency_converter ⇒ Object
39
40
41
|
# File 'lib/spot-rate.rb', line 39
def default_currency_converter
use(:default)
end
|
#spot_rate ⇒ Object
35
36
37
|
# File 'lib/spot-rate.rb', line 35
def spot_rate
default_currency_converter.spot_rate
end
|
#use(requested_converter_key) ⇒ Object
29
30
31
32
33
|
# File 'lib/spot-rate.rb', line 29
def use(requested_converter_key)
self.class
.available_converters[requested_converter_key.to_sym]
.new(@from_currency, @to_currency)
end
|