ecb-currency_converter 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/ecb-currency_converter.gemspec +27 -0
- data/lib/ecb/currency_converter/exceptions.rb +23 -0
- data/lib/ecb/currency_converter/version.rb +5 -0
- data/lib/ecb/currency_converter.rb +107 -0
- data/spec/ecb/currency_converter_spec.rb +139 -0
- data/spec/fixtures/eurofxref-daily.xml +44 -0
- data/spec/spec_helper.rb +20 -0
- metadata +143 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Michael J. Sepcot
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# ECB::CurrencyConverter
|
2
|
+
|
3
|
+
Currency Conversion using the European Central Bank's Euro foreign exchange reference rates.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ecb-currency_converter'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ecb-currency_converter
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To convert between two currencies:
|
22
|
+
|
23
|
+
ECB::CurrencyConverter.exchange(100, 'EUR', 'USD')
|
24
|
+
=> 133.73999999999998
|
25
|
+
|
26
|
+
ECB::CurrencyConverter.exchange(100, 'USD', 'EUR')
|
27
|
+
=> 74.77194556602363
|
28
|
+
|
29
|
+
To get the most recent exchange rate between two currencies:
|
30
|
+
|
31
|
+
ECB::CurrencyConverter.rate('EUR', 'USD')
|
32
|
+
=> 1.3374
|
33
|
+
|
34
|
+
ECB::CurrencyConverter.rate('USD', 'EUR')
|
35
|
+
=> 0.7477194556602363
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ecb/currency_converter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'ecb-currency_converter'
|
8
|
+
spec.version = ECB::CurrencyConverter::VERSION
|
9
|
+
spec.authors = ['Michael J. Sepcot']
|
10
|
+
spec.email = ['developer@sepcot.com']
|
11
|
+
spec.description = %q{Currency Conversion using the European Central Bank's Euro foreign exchange reference rates.}
|
12
|
+
spec.summary = %q{Currency Conversion using the European Central Bank's Euro foreign exchange reference rates.}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'fakeweb'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
|
26
|
+
spec.add_dependency 'httparty', '~> 0.11.0'
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ECB # :nodoc:
|
2
|
+
# = ECB Unknown Currency Error
|
3
|
+
#
|
4
|
+
# Raised when we try to grab data for an unsupported currency code.
|
5
|
+
#
|
6
|
+
# * +currency_code+ - the unsupported ISO 4217 Currency Code.
|
7
|
+
class UnknownCurrencyError < StandardError
|
8
|
+
def initialize(currency_code)
|
9
|
+
super("#{currency_code} is not supported.")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# = ECB Missing Exchange Rate Error
|
14
|
+
#
|
15
|
+
# Raised when the data for a supported currency code is +nil+ or +zero?+.
|
16
|
+
#
|
17
|
+
# * +currency_code+ - the unsupported ISO 4217 Currency Code.
|
18
|
+
class MissingExchangeRateError < StandardError
|
19
|
+
def initialize(currency_code)
|
20
|
+
super("Foreign exchange reference rate for #{currency_code} is missing.")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'ecb/currency_converter/exceptions'
|
2
|
+
require 'ecb/currency_converter/version'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module ECB # :nodoc:
|
6
|
+
# = European Central Bank - Currency Converter
|
7
|
+
#
|
8
|
+
# Convert values or find the most recent foreign exchange reference rate
|
9
|
+
# between any of the +CURRENCIES+ supported by the European Central Bank.
|
10
|
+
#
|
11
|
+
# An overview of the latest Euro foreign exchange reference rates is
|
12
|
+
# avaliable at:
|
13
|
+
#
|
14
|
+
# http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html
|
15
|
+
#
|
16
|
+
module CurrencyConverter
|
17
|
+
DAILY_URI = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'
|
18
|
+
CURRENCIES = [
|
19
|
+
'AUD', # Australian Dollar (A$)
|
20
|
+
'BGN', # Bulgarian Lev (BGN)
|
21
|
+
'BRL', # Brazilian Real (R$)
|
22
|
+
'CAD', # Canadian Dollar (CA$)
|
23
|
+
'CHF', # Swiss Franc (CHF)
|
24
|
+
'CNY', # Chinese Yuan (CN¥)
|
25
|
+
'CZK', # Czech Republic Koruna (CZK)
|
26
|
+
'DKK', # Danish Krone (DKK)
|
27
|
+
'EUR', # Euro (€)
|
28
|
+
'GBP', # British Pound Sterling (£)
|
29
|
+
'HKD', # Hong Kong Dollar (HK$)
|
30
|
+
'HRK', # Croatian Kuna (HRK)
|
31
|
+
'HUF', # Hungarian Forint (HUF)
|
32
|
+
'IDR', # Indonesian Rupiah (IDR)
|
33
|
+
'ILS', # Israeli New Sheqel (₪)
|
34
|
+
'INR', # Indian Rupee (Rs.)
|
35
|
+
'JPY', # Japanese Yen (¥)
|
36
|
+
'KRW', # South Korean Won (₩)
|
37
|
+
'LTL', # Lithuanian Litas (LTL)
|
38
|
+
'LVL', # Latvian Lats (LVL)
|
39
|
+
'MXN', # Mexican Peso (MX$)
|
40
|
+
'MYR', # Malaysian Ringgit (MYR)
|
41
|
+
'NOK', # Norwegian Krone (NOK)
|
42
|
+
'NZD', # New Zealand Dollar (NZ$)
|
43
|
+
'PHP', # Philippine Peso (Php)
|
44
|
+
'PLN', # Polish Zloty (PLN)
|
45
|
+
'RON', # Romanian Leu (RON)
|
46
|
+
'RUB', # Russian Ruble (RUB)
|
47
|
+
'SEK', # Swedish Krona (SEK)
|
48
|
+
'SGD', # Singapore Dollar (SGD)
|
49
|
+
'THB', # Thai Baht (฿)
|
50
|
+
'TRY', # Turkish Lira (TRY)
|
51
|
+
'USD', # US Dollar ($)
|
52
|
+
'ZAR', # South African Rand (ZAR)
|
53
|
+
]
|
54
|
+
|
55
|
+
class << self # Class methods
|
56
|
+
# Converts the +value+ between +from+ and +to+ currencies.
|
57
|
+
#
|
58
|
+
# = Example
|
59
|
+
#
|
60
|
+
# ECB::CurrencyConverter.exchange(100, 'EUR', 'USD')
|
61
|
+
# => 133.73999999999998
|
62
|
+
#
|
63
|
+
# ECB::CurrencyConverter.exchange(100, 'USD', 'EUR')
|
64
|
+
# => 74.77194556602363
|
65
|
+
def exchange(value, from, to)
|
66
|
+
value * rate(from, to)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Return the exchange rate between +from+ and +to+ currencies.
|
70
|
+
#
|
71
|
+
# = Example
|
72
|
+
#
|
73
|
+
# ECB::CurrencyConverter.rate('EUR', 'USD')
|
74
|
+
# => 1.3374
|
75
|
+
#
|
76
|
+
# ECB::CurrencyConverter.rate('USD', 'EUR')
|
77
|
+
# => 0.7477194556602363
|
78
|
+
def rate(from, to)
|
79
|
+
load_data!
|
80
|
+
validate(from, to)
|
81
|
+
|
82
|
+
1.0 / @euro[from] * @euro[to]
|
83
|
+
end
|
84
|
+
private
|
85
|
+
# Load data from European Central Bank's daily XML feed.
|
86
|
+
def load_data!
|
87
|
+
@euro ||= begin
|
88
|
+
response = HTTParty.get(DAILY_URI, format: :xml)
|
89
|
+
|
90
|
+
data = response['Envelope']['Cube']['Cube']['Cube']
|
91
|
+
data = data.reduce({}) { |a,e| a[e['currency']] = e['rate'].to_f; a }
|
92
|
+
data['EUR'] = 1.0
|
93
|
+
data
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Raise errors for invalid currencies or missing data.
|
98
|
+
def validate(from, to)
|
99
|
+
raise UnknownCurrencyError.new(from) unless CURRENCIES.include?(from)
|
100
|
+
raise UnknownCurrencyError.new(to) unless CURRENCIES.include?(to)
|
101
|
+
|
102
|
+
raise MissingExchangeRateError.new(from) if @euro[from].to_f.zero?
|
103
|
+
raise MissingExchangeRateError.new(to) if @euro[to].to_f.zero?
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
|
3
|
+
def rate_comparison(from, to, actual)
|
4
|
+
ECB::CurrencyConverter.rate(from, to).should be_within(0.0001).of(actual)
|
5
|
+
end
|
6
|
+
|
7
|
+
def exchange_comparison(amount, from, to, actual)
|
8
|
+
ECB::CurrencyConverter.exchange(amount, from, to).should(
|
9
|
+
be_within(0.0001).of(actual)
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ECB::CurrencyConverter do
|
14
|
+
describe '#exchange' do
|
15
|
+
it 'should convert between currencies through the EUR' do
|
16
|
+
[ ['AUD', 'LTL', 244.34222], ['BGN', 'LVL', 35.87278],
|
17
|
+
['BRL', 'MXN', 591.82960], ['CAD', 'MYR', 309.46094],
|
18
|
+
['CHF', 'NOK', 624.72594], ['CNY', 'NZD', 20.44337],
|
19
|
+
['CZK', 'PHP', 225.03894], ['DKK', 'PLN', 57.04671],
|
20
|
+
['EUR', 'KRW', 151703.00], ['GBP', 'RON', 525.55477],
|
21
|
+
['HKD', 'RUB', 413.00283], ['HRK', 'SEK', 115.89472],
|
22
|
+
['HUF', 'SGD', 0.57404], ['IDR', 'THB', 0.31147],
|
23
|
+
['ILS', 'TRY', 52.38214], ['INR', 'USD', 1.70152],
|
24
|
+
['JPY', 'ZAR', 10.51728],
|
25
|
+
].each do |from, to, actual|
|
26
|
+
exchange_comparison(100, from, to, actual)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#rate' do
|
32
|
+
it 'should match the provided rates when converting from EUR' do
|
33
|
+
[ ['AUD', 1.4131], ['BGN', 1.9558], ['BRL', 2.9203],
|
34
|
+
['CAD', 1.3635], ['CHF', 1.2315], ['CNY', 8.1963],
|
35
|
+
['CZK', 25.680], ['DKK', 7.4595], ['GBP', 0.85620],
|
36
|
+
['HKD', 10.3762], ['HRK', 7.4855], ['HUF', 293.62],
|
37
|
+
['IDR', 13246.45], ['ILS', 4.8045], ['INR', 78.6000],
|
38
|
+
['JPY', 127.55], ['KRW', 1517.03], ['LTL', 3.4528],
|
39
|
+
['LVL', 0.7016], ['MXN', 17.2832], ['MYR', 4.2195],
|
40
|
+
['NOK', 7.6935], ['NZD', 1.6756], ['PHP', 57.790],
|
41
|
+
['PLN', 4.2554], ['RON', 4.4998], ['RUB', 42.8540],
|
42
|
+
['SEK', 8.6753], ['SGD', 1.6855], ['THB', 41.259],
|
43
|
+
['TRY', 2.5167], ['USD', 1.3374], ['ZAR', 13.4148]
|
44
|
+
].each do |currency, value|
|
45
|
+
rate_comparison('EUR', currency, value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should match the inverted rates when converting to EUR' do
|
50
|
+
[ ['AUD', 1.4131], ['BGN', 1.9558], ['BRL', 2.9203],
|
51
|
+
['CAD', 1.3635], ['CHF', 1.2315], ['CNY', 8.1963],
|
52
|
+
['CZK', 25.680], ['DKK', 7.4595], ['GBP', 0.85620],
|
53
|
+
['HKD', 10.3762], ['HRK', 7.4855], ['HUF', 293.62],
|
54
|
+
['IDR', 13246.45], ['ILS', 4.8045], ['INR', 78.6000],
|
55
|
+
['JPY', 127.55], ['KRW', 1517.03], ['LTL', 3.4528],
|
56
|
+
['LVL', 0.7016], ['MXN', 17.2832], ['MYR', 4.2195],
|
57
|
+
['NOK', 7.6935], ['NZD', 1.6756], ['PHP', 57.790],
|
58
|
+
['PLN', 4.2554], ['RON', 4.4998], ['RUB', 42.8540],
|
59
|
+
['SEK', 8.6753], ['SGD', 1.6855], ['THB', 41.259],
|
60
|
+
['TRY', 2.5167], ['USD', 1.3374], ['ZAR', 13.4148]
|
61
|
+
].each do |currency, value|
|
62
|
+
rate_comparison(currency, 'EUR', 1.0 / value)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should report a rate of 1.0 between the same currency' do
|
67
|
+
rate_comparison('KRW', 'KRW', 1.0)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should convert rates between currencies through the EUR' do
|
71
|
+
[ ['AUD', 'LTL', 2.44342], ['BGN', 'LVL', 0.35872],
|
72
|
+
['BRL', 'MXN', 5.91829], ['CAD', 'MYR', 3.09460],
|
73
|
+
['CHF', 'NOK', 6.24725], ['CNY', 'NZD', 0.20443],
|
74
|
+
['CZK', 'PHP', 2.25038], ['DKK', 'PLN', 0.57046],
|
75
|
+
['GBP', 'RON', 5.25554], ['HKD', 'RUB', 4.13002],
|
76
|
+
['HRK', 'SEK', 1.15894], ['HUF', 'SGD', 0.00574],
|
77
|
+
['IDR', 'THB', 0.00311], ['ILS', 'TRY', 0.52382],
|
78
|
+
['INR', 'USD', 0.01701], ['JPY', 'ZAR', 0.10517],
|
79
|
+
].each do |from, to, value|
|
80
|
+
rate_comparison(from, to, value)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#validate' do
|
85
|
+
describe ECB::UnknownCurrencyError do
|
86
|
+
it 'should raise an error on an unsupported currency code' do
|
87
|
+
expect {
|
88
|
+
ECB::CurrencyConverter.exchange(100, 'USD', 'UNKNOWN')
|
89
|
+
}.to raise_error(ECB::UnknownCurrencyError)
|
90
|
+
|
91
|
+
expect {
|
92
|
+
ECB::CurrencyConverter.exchange(100, 'UNKNOWN', 'USD')
|
93
|
+
}.to raise_error(ECB::UnknownCurrencyError)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should not raise an error for supported currency codes' do
|
97
|
+
expect {
|
98
|
+
ECB::CurrencyConverter.exchange(100, 'EUR', 'USD')
|
99
|
+
}.to_not raise_error(ECB::UnknownCurrencyError)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe ECB::MissingExchangeRateError do
|
104
|
+
before do
|
105
|
+
ECB::CurrencyConverter.send(:load_data!)
|
106
|
+
|
107
|
+
euro = ECB::CurrencyConverter.instance_variable_get(:@euro)
|
108
|
+
euro['USD'] = nil
|
109
|
+
|
110
|
+
ECB::CurrencyConverter.instance_variable_set(:@euro, euro)
|
111
|
+
end
|
112
|
+
|
113
|
+
after do
|
114
|
+
ECB::CurrencyConverter.instance_variable_set(:@euro, nil)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should raise an error if supported data is missing' do
|
118
|
+
expect {
|
119
|
+
ECB::CurrencyConverter.exchange(100, 'EUR', 'USD')
|
120
|
+
}.to raise_error(ECB::MissingExchangeRateError)
|
121
|
+
|
122
|
+
expect {
|
123
|
+
ECB::CurrencyConverter.exchange(100, 'USD', 'EUR')
|
124
|
+
}.to raise_error(ECB::MissingExchangeRateError)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should not raise an error if we have data available' do
|
128
|
+
expect {
|
129
|
+
ECB::CurrencyConverter.exchange(100, 'EUR', 'GBP')
|
130
|
+
}.to_not raise_error(ECB::MissingExchangeRateError)
|
131
|
+
|
132
|
+
expect {
|
133
|
+
ECB::CurrencyConverter.exchange(100, 'GBP', 'EUR')
|
134
|
+
}.to_not raise_error(ECB::MissingExchangeRateError)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
|
3
|
+
<gesmes:subject>Reference rates</gesmes:subject>
|
4
|
+
<gesmes:Sender>
|
5
|
+
<gesmes:name>European Central Bank</gesmes:name>
|
6
|
+
</gesmes:Sender>
|
7
|
+
<Cube>
|
8
|
+
<Cube time="2013-06-18">
|
9
|
+
<Cube currency="USD" rate="1.3374"/>
|
10
|
+
<Cube currency="JPY" rate="127.55"/>
|
11
|
+
<Cube currency="BGN" rate="1.9558"/>
|
12
|
+
<Cube currency="CZK" rate="25.680"/>
|
13
|
+
<Cube currency="DKK" rate="7.4595"/>
|
14
|
+
<Cube currency="GBP" rate="0.85620"/>
|
15
|
+
<Cube currency="HUF" rate="293.62"/>
|
16
|
+
<Cube currency="LTL" rate="3.4528"/>
|
17
|
+
<Cube currency="LVL" rate="0.7016"/>
|
18
|
+
<Cube currency="PLN" rate="4.2554"/>
|
19
|
+
<Cube currency="RON" rate="4.4998"/>
|
20
|
+
<Cube currency="SEK" rate="8.6753"/>
|
21
|
+
<Cube currency="CHF" rate="1.2315"/>
|
22
|
+
<Cube currency="NOK" rate="7.6935"/>
|
23
|
+
<Cube currency="HRK" rate="7.4855"/>
|
24
|
+
<Cube currency="RUB" rate="42.8540"/>
|
25
|
+
<Cube currency="TRY" rate="2.5167"/>
|
26
|
+
<Cube currency="AUD" rate="1.4131"/>
|
27
|
+
<Cube currency="BRL" rate="2.9203"/>
|
28
|
+
<Cube currency="CAD" rate="1.3635"/>
|
29
|
+
<Cube currency="CNY" rate="8.1963"/>
|
30
|
+
<Cube currency="HKD" rate="10.3762"/>
|
31
|
+
<Cube currency="IDR" rate="13246.45"/>
|
32
|
+
<Cube currency="ILS" rate="4.8045"/>
|
33
|
+
<Cube currency="INR" rate="78.6000"/>
|
34
|
+
<Cube currency="KRW" rate="1517.03"/>
|
35
|
+
<Cube currency="MXN" rate="17.2832"/>
|
36
|
+
<Cube currency="MYR" rate="4.2195"/>
|
37
|
+
<Cube currency="NZD" rate="1.6756"/>
|
38
|
+
<Cube currency="PHP" rate="57.790"/>
|
39
|
+
<Cube currency="SGD" rate="1.6855"/>
|
40
|
+
<Cube currency="THB" rate="41.259"/>
|
41
|
+
<Cube currency="ZAR" rate="13.4148"/>
|
42
|
+
</Cube>
|
43
|
+
</Cube>
|
44
|
+
</gesmes:Envelope>
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'ecb/currency_converter'
|
5
|
+
require 'fakeweb'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.before(:suite) do
|
9
|
+
FakeWeb.allow_net_connect = false
|
10
|
+
|
11
|
+
xml = File.read(File.expand_path(
|
12
|
+
File.join(File.dirname(__FILE__), 'fixtures', 'eurofxref-daily.xml')
|
13
|
+
))
|
14
|
+
FakeWeb.register_uri(:get, ECB::CurrencyConverter::DAILY_URI, body: xml)
|
15
|
+
end
|
16
|
+
|
17
|
+
config.after(:suite) do
|
18
|
+
FakeWeb.allow_net_connect = true
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ecb-currency_converter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael J. Sepcot
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: fakeweb
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: httparty
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.11.0
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.11.0
|
94
|
+
description: Currency Conversion using the European Central Bank's Euro foreign exchange
|
95
|
+
reference rates.
|
96
|
+
email:
|
97
|
+
- developer@sepcot.com
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- ecb-currency_converter.gemspec
|
108
|
+
- lib/ecb/currency_converter.rb
|
109
|
+
- lib/ecb/currency_converter/exceptions.rb
|
110
|
+
- lib/ecb/currency_converter/version.rb
|
111
|
+
- spec/ecb/currency_converter_spec.rb
|
112
|
+
- spec/fixtures/eurofxref-daily.xml
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
homepage: ''
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 1.8.23
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: Currency Conversion using the European Central Bank's Euro foreign exchange
|
139
|
+
reference rates.
|
140
|
+
test_files:
|
141
|
+
- spec/ecb/currency_converter_spec.rb
|
142
|
+
- spec/fixtures/eurofxref-daily.xml
|
143
|
+
- spec/spec_helper.rb
|