cnb 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +89 -0
- data/cnb.gemspec +26 -0
- data/config/cnb.yml.example +1 -0
- data/lib/cnb/cur_rates_parser.rb +67 -0
- data/lib/cnb/daily_cur_rates_parser.rb +23 -0
- data/lib/cnb/load_config.rb +15 -0
- data/lib/cnb/monthly_cur_rates_parser.rb +32 -0
- data/lib/cnb/version.rb +3 -0
- data/lib/cnb.rb +34 -0
- data/spec/examples/daily_cur_rates.txt +35 -0
- data/spec/examples/monthly_cur_rates_2013_3.txt +126 -0
- data/spec/models/daily_cur_rates_parser_spec.rb +31 -0
- data/spec/models/monthly_cur_rates_parser_spec.rb +43 -0
- data/spec/spec_helper.rb +23 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7258b91abda4684ba20e7f057cacc405608eac4d
|
4
|
+
data.tar.gz: f5218a603a1f96285627001d9ed4b8f890aae7f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: faf1a3221cb1a415ac00cfac3bb31503a5aaf433abeb47490311ffd7d7fe3984aeaa79b547b1351a08d0c114eecfea3ad02d84fa698a75494f7e7bb9a77bb745
|
7
|
+
data.tar.gz: d9cdce86836c8179dc0bbb86154acd1b3662cb1ae7f896791d3c599150436d79e570fa87fc4e5ac26b6c4f8219e30a1b19e6d50e15286c96c190f010831bc4f1
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Účetnictví on-line
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# CNB [![Build Status](https://travis-ci.org/ucetnictvi-on-line/cnb.png?branch=master)](https://travis-ci.org/ucetnictvi-on-line/cnb)
|
2
|
+
|
3
|
+
CNB is a gem that will help you get daily and monthly currency rates for czech crown (CZK) from Czech National Bank. Besides the currency rate you can also get name of the currency, name of the country where it is used and date when the currency rates were published.
|
4
|
+
|
5
|
+
|
6
|
+
## Install
|
7
|
+
|
8
|
+
Add following into your Gemfile
|
9
|
+
|
10
|
+
gem 'cnb'
|
11
|
+
|
12
|
+
Run
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install the gem by on your own
|
17
|
+
|
18
|
+
$ gem install cnb
|
19
|
+
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
|
24
|
+
### Daily currency rates
|
25
|
+
To work with current currency rates start with the following code:
|
26
|
+
|
27
|
+
CNB.daily_rates
|
28
|
+
|
29
|
+
Get currency rate of currency towards czech crown (CZK) with given currency code
|
30
|
+
|
31
|
+
CNB.rate('USD') # 19.927 (float value)
|
32
|
+
|
33
|
+
Get name of the currency in czech language.
|
34
|
+
|
35
|
+
CNB.name('USD') # dolar
|
36
|
+
|
37
|
+
Get name of the country where the currency comes from in czech language.
|
38
|
+
|
39
|
+
CNB.country('USD') # USA
|
40
|
+
|
41
|
+
Get date when the currency rates were published. Czech National Bank does not publish currency rates during the weekend, so may want to check when exactly were the values published.
|
42
|
+
|
43
|
+
CNB.date
|
44
|
+
|
45
|
+
|
46
|
+
### Monthly currency rates
|
47
|
+
|
48
|
+
Some currency rates are published on monthly basis. You can get currency rates for any month and year since 2004.
|
49
|
+
|
50
|
+
To get the monthly currency rates use the following code:
|
51
|
+
|
52
|
+
# Get currency rates for March 2013
|
53
|
+
CNB.monthly_rates(3, 2013)
|
54
|
+
|
55
|
+
After using the code above, you can use the same methods as for the daily currency rates.
|
56
|
+
|
57
|
+
CNB.rate('HNL')
|
58
|
+
CNB.name('HNL') # lempira
|
59
|
+
CNB.country('HNL') # Honduras
|
60
|
+
CNB.date
|
61
|
+
|
62
|
+
|
63
|
+
### Primary currency
|
64
|
+
|
65
|
+
Czech National Bank provides all currency rates towards czech crown (CZK). You can get the primary currency with the following code
|
66
|
+
|
67
|
+
CNB::PRIMARY_CURRENCY # CZK
|
68
|
+
|
69
|
+
|
70
|
+
## Configuration
|
71
|
+
|
72
|
+
The currency rates are downloaded to your disk so you don't have to download them repeatedly. You can set directory where the files should be stored in the configuration file
|
73
|
+
|
74
|
+
config/cnb.yml
|
75
|
+
|
76
|
+
If configuration file is missing files are downloaded into /tmp directory.
|
77
|
+
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
1. Fork it
|
82
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
83
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
84
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
85
|
+
5. Create new Pull Request
|
86
|
+
|
87
|
+
|
88
|
+
## License
|
89
|
+
MIT License. Copyright (c) 2014
|
data/cnb.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
require 'cnb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'cnb'
|
8
|
+
s.version = CNB::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ['Jan Zikán']
|
11
|
+
s.email = ['zikan@uol.cz']
|
12
|
+
s.summary = 'CNB currency rates'
|
13
|
+
s.description = 'Gem for downloading and parsing currency rates from Czech National Bank'
|
14
|
+
s.homepage = 'http://www.uol.cz'
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n") - Dir["images/*"]
|
18
|
+
s.test_files = `git ls-files -- spec/**/*`.split("\n")
|
19
|
+
|
20
|
+
s.require_paths = ['lib', 'config']
|
21
|
+
|
22
|
+
s.add_development_dependency('pry', '~> 0.9')
|
23
|
+
s.add_development_dependency('rake', '~> 0.9')
|
24
|
+
s.add_development_dependency('rspec', '~> 2.14')
|
25
|
+
s.add_development_dependency('simplecov', '~> 0.8')
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
exchange_rates_dir: /tmp
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
module CNB
|
4
|
+
class CurRatesParser
|
5
|
+
CUR_RATES_URL = 'http://www.cnb.cz/cs/financni_trhy/devizovy_trh/'
|
6
|
+
|
7
|
+
attr_reader :cur_rates_filepath, :date
|
8
|
+
|
9
|
+
def rate(cur_code)
|
10
|
+
get_currency(cur_code)[:rate]
|
11
|
+
end
|
12
|
+
|
13
|
+
def name(cur_code)
|
14
|
+
get_currency(cur_code)[:name]
|
15
|
+
end
|
16
|
+
|
17
|
+
def country(cur_code)
|
18
|
+
get_currency(cur_code)[:country]
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def get_currency(cur_code)
|
24
|
+
raise 'Currency with given code was not found in exchange rates list' unless @currencies[cur_code]
|
25
|
+
@currencies[cur_code]
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse(filepath)
|
29
|
+
@date = parse_date(filepath)
|
30
|
+
cur_rates = File.read(filepath)
|
31
|
+
lines = cur_rates.lines.to_a
|
32
|
+
|
33
|
+
lines.shift(2)
|
34
|
+
lines.each do |line|
|
35
|
+
cur = parse_cur(line)
|
36
|
+
@currencies[cur[:cur_code]] = cur[:data]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def parse_cur(line)
|
41
|
+
columns = line.split('|')
|
42
|
+
amount = columns[2].to_f
|
43
|
+
rate = columns[4].chomp.tr(',', '.').to_f
|
44
|
+
|
45
|
+
data = { country: columns[0], name: columns[1], rate: rate / amount }
|
46
|
+
{ cur_code: columns[3], data: data }
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse_date(filepath)
|
50
|
+
line = File.open(filepath) { |f| f.readline }
|
51
|
+
date = line[0..line.index('#') - 1].chomp
|
52
|
+
Date.parse(date)
|
53
|
+
end
|
54
|
+
|
55
|
+
def download_cur_rates(url)
|
56
|
+
content = get_page_content(url)
|
57
|
+
f = File.new(@cur_rates_filepath, 'w')
|
58
|
+
f.write(content)
|
59
|
+
f.close
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_page_content(url)
|
63
|
+
file = open(url)
|
64
|
+
file.read
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CNB
|
2
|
+
class DailyCurRatesParser < CurRatesParser
|
3
|
+
def initialize
|
4
|
+
@currencies = {}
|
5
|
+
@cur_rates_url = "#{CUR_RATES_URL}kurzy_devizoveho_trhu/denni_kurz.txt"
|
6
|
+
@cur_rates_filepath = "#{CONFIG['exchange_rates_dir']}/daily_cur_rates.txt"
|
7
|
+
|
8
|
+
parse
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def parse
|
14
|
+
if File.exist?(cur_rates_filepath)
|
15
|
+
download_cur_rates(@cur_rates_url) unless parse_date(cur_rates_filepath) == Date.today
|
16
|
+
else
|
17
|
+
download_cur_rates(@cur_rates_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
super(cur_rates_filepath)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
if File.exists?('config/cnb.yml')
|
4
|
+
filename = 'config/cnb.yml'
|
5
|
+
elsif File.exists?(ENV['HOME'] + '/.cnb.yml')
|
6
|
+
filename = ENV['HOME'] + '/.cnb.yml'
|
7
|
+
end
|
8
|
+
|
9
|
+
if filename
|
10
|
+
CONFIG = YAML.load_file(filename)
|
11
|
+
else
|
12
|
+
CONFIG = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
CONFIG['exchange_rates_dir'] ||= '/tmp'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module CNB
|
2
|
+
class MonthlyCurRatesParser < CurRatesParser
|
3
|
+
def initialize(month, year)
|
4
|
+
@month = month
|
5
|
+
@year = year
|
6
|
+
|
7
|
+
raise 'Invalid year given' unless valid_month?
|
8
|
+
raise 'Invalid month given' unless valid_year?
|
9
|
+
|
10
|
+
@currencies = {}
|
11
|
+
@cur_rates_url = "#{CUR_RATES_URL}/kurzy_ostatnich_men/kurzy.txt?mesic=#{month}&rok=#{year}"
|
12
|
+
@cur_rates_filepath = "#{CONFIG['exchange_rates_dir']}/monthly_cur_rates_#{year}_#{month}.txt"
|
13
|
+
|
14
|
+
parse
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def parse
|
20
|
+
download_cur_rates(@cur_rates_url) unless File.exist?(cur_rates_filepath)
|
21
|
+
super(cur_rates_filepath)
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid_month?
|
25
|
+
@month.to_i >= 1 && @month.to_i <= 12
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid_year?
|
29
|
+
@year.to_i >= 2004 && @year.to_i <= Time.now.year
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/cnb/version.rb
ADDED
data/lib/cnb.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'cnb/load_config'
|
2
|
+
require_relative 'cnb/cur_rates_parser'
|
3
|
+
require_relative 'cnb/daily_cur_rates_parser'
|
4
|
+
require_relative 'cnb/monthly_cur_rates_parser'
|
5
|
+
|
6
|
+
module CNB
|
7
|
+
PRIMARY_CURRENCY = 'CZK'
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def daily_rates
|
11
|
+
@parser = DailyCurRatesParser.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def monthly_rates(month, year)
|
15
|
+
@parser = MonthlyCurRatesParser.new(month, year)
|
16
|
+
end
|
17
|
+
|
18
|
+
def date
|
19
|
+
@parser.date
|
20
|
+
end
|
21
|
+
|
22
|
+
def rate(cur_code)
|
23
|
+
@parser.rate(cur_code)
|
24
|
+
end
|
25
|
+
|
26
|
+
def name(cur_code)
|
27
|
+
@parser.name(cur_code)
|
28
|
+
end
|
29
|
+
|
30
|
+
def country(cur_code)
|
31
|
+
@parser.country(cur_code)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
24.02.2014 #38
|
2
|
+
země|měna|množství|kód|kurz
|
3
|
+
Austrálie|dolar|1|AUD|17,919
|
4
|
+
Brazílie|real|1|BRL|8,503
|
5
|
+
Bulharsko|lev|1|BGN|13,990
|
6
|
+
Čína|renminbi|1|CNY|3,268
|
7
|
+
Dánsko|koruna|1|DKK|3,667
|
8
|
+
EMU|euro|1|EUR|27,365
|
9
|
+
Filipíny|peso|100|PHP|44,690
|
10
|
+
Hongkong|dolar|1|HKD|2,568
|
11
|
+
Chorvatsko|kuna|1|HRK|3,570
|
12
|
+
Indie|rupie|100|INR|32,102
|
13
|
+
Indonesie|rupie|1000|IDR|1,711
|
14
|
+
Izrael|šekel|1|ILS|5,686
|
15
|
+
Japonsko|jen|100|JPY|19,453
|
16
|
+
Jihoafrická rep.|rand|1|ZAR|1,825
|
17
|
+
Jižní Korea|won|100|KRW|1,854
|
18
|
+
Kanada|dolar|1|CAD|17,955
|
19
|
+
Litva|litas|1|LTL|7,926
|
20
|
+
Maďarsko|forint|100|HUF|8,823
|
21
|
+
Malajsie|ringgit|1|MYR|6,070
|
22
|
+
Mexiko|peso|1|MXN|1,503
|
23
|
+
MMF|SDR|1|XDR|30,765
|
24
|
+
Norsko|koruna|1|NOK|3,305
|
25
|
+
Nový Zéland|dolar|1|NZD|16,527
|
26
|
+
Polsko|zlotý|1|PLN|6,581
|
27
|
+
Rumunsko|nové leu|1|RON|6,068
|
28
|
+
Rusko|rubl|100|RUB|56,033
|
29
|
+
Singapur|dolar|1|SGD|15,740
|
30
|
+
Švédsko|koruna|1|SEK|3,062
|
31
|
+
Švýcarsko|frank|1|CHF|22,411
|
32
|
+
Thajsko|baht|100|THB|61,220
|
33
|
+
Turecko|lira|1|TRY|9,154
|
34
|
+
USA|dolar|1|USD|19,927
|
35
|
+
Velká Británie|libra|1|GBP|33,184
|
@@ -0,0 +1,126 @@
|
|
1
|
+
29.03.2013 #3
|
2
|
+
země|měna|množství|kód|kurz
|
3
|
+
Afghánistán|afghani|100|AFN|38,167
|
4
|
+
Albánie|lek|100|ALL|18,474
|
5
|
+
Alžírsko|dinár|100|DZD|25,454
|
6
|
+
Angola|kwanza|100|AOA|20,964
|
7
|
+
Argentina|peso|1|ARS|3,921
|
8
|
+
Arménie|dram|100|AMD|4,808
|
9
|
+
Aruba|gulden|1|AWG|11,276
|
10
|
+
Ázerbájdžán|manat|1|AZN|25,622
|
11
|
+
Bahamy|dolar|1|BSD|20,072
|
12
|
+
Bahrajn|dinár|1|BHD|53,246
|
13
|
+
Bangladéš|taka|100|BDT|25,717
|
14
|
+
Barbados|dolar|1|BBD|10,036
|
15
|
+
Belize|dolar|1|BZD|9,937
|
16
|
+
Bělorusko|rubl|100|BYR|0,233
|
17
|
+
Bermudy|dolar|1|BMD|20,072
|
18
|
+
Bhútán|ngultrum|100|BTN|36,979
|
19
|
+
Bolivie|boliviano|1|BOB|2,884
|
20
|
+
Bosna a Hercegovina|marka|1|BAM|13,158
|
21
|
+
Botswana|pula|1|BWP|2,429
|
22
|
+
Brunej|dolar|1|BND|16,179
|
23
|
+
Burundi|frank|100|BIF|1,294
|
24
|
+
Cape Verde|escudo|100|CVE|23,457
|
25
|
+
Curacao a St. Marteen|gulden|1|ANG|11,276
|
26
|
+
Dominikánská republika|peso|100|DOP|49,136
|
27
|
+
Džibutsko|frank|100|DJF|11,489
|
28
|
+
Egypt|libra|1|EGP|2,950
|
29
|
+
Eritrea|nakfa|1|ERN|1,379
|
30
|
+
Etiopie|birr|1|ETB|1,090
|
31
|
+
Falklandy|libra|1|FKP|30,520
|
32
|
+
Fidži|dolar|1|FJD|11,142
|
33
|
+
Francouzská Polynésie|frank CFP|100|XPF|21,695
|
34
|
+
Gambie|dalasi|100|GMD|62,725
|
35
|
+
Ghana|Ghana cedi|1|GHS|10,360
|
36
|
+
Gibraltar|libra|1|GIP|30,520
|
37
|
+
Gruzie|lari|1|GEL|12,108
|
38
|
+
Guatemala|quetzal|1|GTQ|2,581
|
39
|
+
Guinea|frank|1000|GNF|2,896
|
40
|
+
Guyana|dolar|100|GYD|9,926
|
41
|
+
Haiti|gourde|100|HTG|47,228
|
42
|
+
Honduras|lempira|1|HNL|1,024
|
43
|
+
Chile|peso|100|CLP|4,258
|
44
|
+
Irák|dinar|1000|IQD|17,303
|
45
|
+
Írán|rial|1000|IRR|1,637
|
46
|
+
Island|koruna|100|ISK|16,227
|
47
|
+
Jamajka|dolar|100|JMD|20,597
|
48
|
+
Jemen|rial|100|YER|9,368
|
49
|
+
Jordánsko|dinár|1|JOD|28,354
|
50
|
+
Kajmanské ostrovy|dolar|1|KYD|24,478
|
51
|
+
Kambodža|riel|1000|KHR|5,041
|
52
|
+
Katar|rial|1|QAR|5,513
|
53
|
+
Kazachstán|tenge|100|KZT|13,302
|
54
|
+
Keňa|šilink|100|KES|23,586
|
55
|
+
KLDR|won|1|KPW|15,440
|
56
|
+
Kolumbie|peso|1000|COP|11,016
|
57
|
+
Komory|frank|100|KMF|5,234
|
58
|
+
Konžská demokratická republika|frank|100|CDF|2,220
|
59
|
+
Kostarika|colon|100|CRC|4,027
|
60
|
+
Kuba|peso|1|CUP|20,072
|
61
|
+
Kuvajt|dinár|1|KWD|70,478
|
62
|
+
Kyrgyzstán|som|100|KGS|42,465
|
63
|
+
Laos|kip|1000|LAK|2,570
|
64
|
+
Lesotho|loti|1|LSL|2,175
|
65
|
+
Libanon|libra|1000|LBP|13,372
|
66
|
+
Libérie|dolar|100|LRD|27,216
|
67
|
+
Libye|dinár|1|LYD|15,664
|
68
|
+
Macao|pataca|1|MOP|2,513
|
69
|
+
Madagaskar|ariary|1000|MGA|8,977
|
70
|
+
Makedonie|denár|100|MKD|42,301
|
71
|
+
Malawi|kwacha|100|MWK|5,282
|
72
|
+
Maledivy|rufiya|1|MVR|1,321
|
73
|
+
Maroko|dirham|1|MAD|2,321
|
74
|
+
Mauritánie|ouguiya|100|MRO|7,299
|
75
|
+
Mauritius|rupie|100|MUR|64,644
|
76
|
+
Moldávie|leu|1|MDL|1,625
|
77
|
+
Mongolsko|tugrik|100|MNT|1,439
|
78
|
+
Mosambik|nový metical|1000|MZN|669,067
|
79
|
+
Myanmar|kyat|1|MMK|0,023
|
80
|
+
Namibie|dolar|1|NAD|2,175
|
81
|
+
Nepál|rupie|100|NPR|23,242
|
82
|
+
Nigérie|naira|100|NGN|12,668
|
83
|
+
Nikaragua|cordoba |1|NIO|0,829
|
84
|
+
Omán|rial|1|OMR|52,139
|
85
|
+
Pákistán|rupie|100|PKR|20,409
|
86
|
+
Panama|balboa|1|PAB|20,072
|
87
|
+
Papua-Nová Quinea|kina|1|PGK|9,103
|
88
|
+
Paraguay|guarani|1000|PYG|5,018
|
89
|
+
Peru|nuevo sol|1|PEN|7,754
|
90
|
+
Rwanda|frank|100|RWF|3,186
|
91
|
+
Salvádor|colon|1|SVC|2,296
|
92
|
+
Samoa|tala|1|WST|8,659
|
93
|
+
Saudská Arábie|riyal|1|SAR|5,352
|
94
|
+
Seychely|rupie|1|SCR|1,781
|
95
|
+
Sierra-Leone|leone|1000|SLL|4,647
|
96
|
+
Somálsko|šilink|1000|SOS|13,231
|
97
|
+
Spojené arabské emiráty|dirham|1|AED|5,465
|
98
|
+
Srbsko|dinár|100|RSD|23,100
|
99
|
+
Srí Lanka|rupie|100|LKR|15,842
|
100
|
+
Státy střední Afriky|frank CFA|100|XAF|3,924
|
101
|
+
Státy západní Afriky|frank CFA|100|XOF|3,924
|
102
|
+
Súdán|libra|1|SDG|4,562
|
103
|
+
Surinam|dolar|1|SRD|6,176
|
104
|
+
Svatá Helena|libra|1|SHP|30,520
|
105
|
+
Svatý Tomáš a Princův ostrov|dobra|1000|STD|1,083
|
106
|
+
Svazijsko|lilangeni|1|SZL|2,175
|
107
|
+
Sýrie|libra|100|SYP|28,503
|
108
|
+
Šalomounovy ostrovy|dolar|1|SBD|2,740
|
109
|
+
Tádžikistán|somoni|1|TJS|4,222
|
110
|
+
Taiwan|dolar|100|TWD|67,333
|
111
|
+
Tanzanie|šilink|100|TZS|1,245
|
112
|
+
Tonga|pa`anga|1|TOP|11,453
|
113
|
+
Trinidad a Tobago|dolar|1|TTD|3,141
|
114
|
+
Tunisko|dinár|1|TND|12,596
|
115
|
+
Turkmenistán|nový manat|1|TMT|7,055
|
116
|
+
Uganda|šilink|100|UGX|0,777
|
117
|
+
Ukrajina|hřivna|1|UAH|2,468
|
118
|
+
Uruguay|peso|100|UYU|106,766
|
119
|
+
Uzbekistán|sum|100|UZS|0,993
|
120
|
+
Vanuatu|vatu|100|VUV|22,128
|
121
|
+
Venezuela|bolivar|1|VEF|3,194
|
122
|
+
Vietnam|dong|1000|VND|0,959
|
123
|
+
Východní Timor|escudo|1|TPE|20,072
|
124
|
+
Východokaribská oblast|dolar|1|XCD|7,518
|
125
|
+
Zambie|kwacha|1|ZMW|3,741
|
126
|
+
Zimbabwe|dolar|1000|ZWL|0,000
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CNB::DailyCurRatesParser do
|
4
|
+
before(:each) do
|
5
|
+
filepath = File.join('spec', 'examples', 'daily_cur_rates.txt')
|
6
|
+
CNB::DailyCurRatesParser.any_instance.stub(:cur_rates_filepath) { filepath }
|
7
|
+
@parser = CNB::DailyCurRatesParser.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns date from the exchange rates file' do
|
11
|
+
expect(@parser.date).to eq Date.parse('24.2.2014')
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#cur_rate' do
|
15
|
+
it 'returns currency rate' do
|
16
|
+
expect(@parser.rate('USD')).to eq(19.927)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'raises error if currency with given code is not included in the exchange rates file' do
|
20
|
+
expect{@parser.rate('USX')}.to raise_error(StandardError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns country name' do
|
25
|
+
expect(@parser.name('USD')).to eq('dolar')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns currency name' do
|
29
|
+
expect(@parser.country('USD')).to eq('USA')
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CNB::MonthlyCurRatesParser do
|
4
|
+
before(:each) do
|
5
|
+
filepath = File.join('spec', 'examples', 'monthly_cur_rates_2013_3.txt')
|
6
|
+
CNB::MonthlyCurRatesParser.any_instance.stub(:cur_rates_filepath) { filepath }
|
7
|
+
@parser = CNB::MonthlyCurRatesParser.new(3, 2013)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'raises error if required month is invalid' do
|
11
|
+
expect{CNB::MonthlyCurRatesParser.new('abc', 2013)}.to raise_error(StandardError)
|
12
|
+
expect{CNB::MonthlyCurRatesParser.new(0, 2013)}.to raise_error(StandardError)
|
13
|
+
expect{CNB::MonthlyCurRatesParser.new(13, 2013)}.to raise_error(StandardError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'raises error if required year is invalid' do
|
17
|
+
expect{CNB::MonthlyCurRatesParser.new(3, 'abc')}.to raise_error(StandardError)
|
18
|
+
expect{CNB::MonthlyCurRatesParser.new(3, 2000)}.to raise_error(StandardError)
|
19
|
+
expect{CNB::MonthlyCurRatesParser.new(3, 2050)}.to raise_error(StandardError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns date from the exchange rates file' do
|
23
|
+
expect(@parser.date).to eq Date.parse('29.3.2013')
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#cur_rate' do
|
27
|
+
it 'returns currency rate' do
|
28
|
+
expect(@parser.rate('HNL')).to eq(1.024)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'raises error if currency wth given code is not included in the exchange rates file' do
|
32
|
+
expect{@parser.rate('HNX')}.to raise_error(StandardError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns country name' do
|
37
|
+
expect(@parser.country('HNL')).to eq('Honduras')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns currency name' do
|
41
|
+
expect(@parser.name('HNL')).to eq('lempira')
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# COVERAGE=true rspec
|
4
|
+
if ENV['COVERAGE']
|
5
|
+
require 'simplecov'
|
6
|
+
SimpleCov.start
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'cnb/load_config'
|
10
|
+
require 'cnb/cur_rates_parser'
|
11
|
+
require 'cnb/daily_cur_rates_parser'
|
12
|
+
require 'cnb/monthly_cur_rates_parser'
|
13
|
+
|
14
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
15
|
+
# in spec/support/ and its subdirectories.
|
16
|
+
Dir[File.join('spec/support/**/*.rb')].each { |f| require f }
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.expect_with :rspec do |c|
|
20
|
+
# disable the `should` syntax
|
21
|
+
c.syntax = :expect
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cnb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Zikán
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
description: Gem for downloading and parsing currency rates from Czech National Bank
|
70
|
+
email:
|
71
|
+
- zikan@uol.cz
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- .travis.yml
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- cnb.gemspec
|
83
|
+
- config/cnb.yml.example
|
84
|
+
- lib/cnb.rb
|
85
|
+
- lib/cnb/cur_rates_parser.rb
|
86
|
+
- lib/cnb/daily_cur_rates_parser.rb
|
87
|
+
- lib/cnb/load_config.rb
|
88
|
+
- lib/cnb/monthly_cur_rates_parser.rb
|
89
|
+
- lib/cnb/version.rb
|
90
|
+
- spec/examples/daily_cur_rates.txt
|
91
|
+
- spec/examples/monthly_cur_rates_2013_3.txt
|
92
|
+
- spec/models/daily_cur_rates_parser_spec.rb
|
93
|
+
- spec/models/monthly_cur_rates_parser_spec.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
homepage: http://www.uol.cz
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
- config
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.2.2
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: CNB currency rates
|
120
|
+
test_files:
|
121
|
+
- spec/examples/daily_cur_rates.txt
|
122
|
+
- spec/examples/monthly_cur_rates_2013_3.txt
|
123
|
+
- spec/models/daily_cur_rates_parser_spec.rb
|
124
|
+
- spec/models/monthly_cur_rates_parser_spec.rb
|