cnb 0.1.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -12
- data/lib/cnb/currency_rates.rb +2 -0
- data/lib/cnb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9351e3fb55843dc18b709b659c1e4ba66a2ff569
|
4
|
+
data.tar.gz: 24e90dc3a78adec9b85fd123753c9f3f213d00b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5db0209ee7192c1ae21bc9f7dd812f492c194adac35cf7f02a5205b3fb23fb9e329e425e603e939087cf9a29a2b5767d724ec80219fe9106c78a171689f7cde8
|
7
|
+
data.tar.gz: a92319e72641dc7cd81c30bffc05c9ce7bc13a17bf9810e254b3a91b60fda6d76a9d84de54a11208458091e46a7b9e017a8fc312683ae1963a1ec1ed301d62e5
|
data/README.md
CHANGED
@@ -25,29 +25,42 @@ Or install the gem by on your own
|
|
25
25
|
|
26
26
|
|
27
27
|
### Daily currency rates
|
28
|
-
To work with
|
28
|
+
To work with daily currency rates start with the following code:
|
29
29
|
|
30
30
|
CNB.daily_rates
|
31
31
|
|
32
|
-
|
32
|
+
This will provide you object from which you can get the currency rates and other information. Everytime you use the code above, actual currency rates are retrived from Czech National Bank, so it is a good idea to assign the result to variable if you don't want to make more HTTP requests than neccessary.
|
33
33
|
|
34
|
-
|
34
|
+
Get currency rate of currency with given currency code towards czech crown (CZK)
|
35
|
+
|
36
|
+
CNB.daily_rates.rate('USD') # 19.927 (float value)
|
37
|
+
CNB.daily_rates.rate('EUR') # 27.34
|
38
|
+
|
39
|
+
By using the code above you make 2 requests for currency rates.
|
40
|
+
|
41
|
+
The following code does the same thing but it retrives the currency rates just once.
|
42
|
+
|
43
|
+
daily_rates = CNB.daily_rates
|
44
|
+
daily_rates.rate('USD')
|
45
|
+
daily_rates.rate('EUR')
|
35
46
|
|
36
47
|
Get name of the currency in czech language.
|
37
48
|
|
38
|
-
CNB.name('USD') # dolar
|
49
|
+
CNB.daily_rates.name('USD') # dolar
|
39
50
|
|
40
51
|
Get name of the country where the currency comes from in czech language.
|
41
52
|
|
42
|
-
CNB.country('USD') # USA
|
53
|
+
CNB.daily_rates.country('USD') # USA
|
43
54
|
|
44
|
-
The currency code is not case sensitive
|
55
|
+
**The currency code parameter is not case sensitive.**
|
45
56
|
|
46
|
-
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.
|
57
|
+
Get date when the currency rates were published. Czech National Bank does not publish currency rates during the weekend, so you may want to check when exactly were the values published.
|
47
58
|
|
48
59
|
CNB.date
|
49
60
|
|
50
|
-
|
61
|
+
You can get all currencies as hash where currency codes are used as keys by the following code
|
62
|
+
|
63
|
+
CNB.daily_rates.currencies
|
51
64
|
|
52
65
|
|
53
66
|
### Monthly currency rates
|
@@ -59,12 +72,19 @@ To get the monthly currency rates use the following code:
|
|
59
72
|
# Get currency rates for March 2013
|
60
73
|
CNB.monthly_rates(3, 2013)
|
61
74
|
|
75
|
+
You can only retrieve monthly currency rates that were published since 2004. If you try to get older currency rates, exception will be raised.
|
76
|
+
|
62
77
|
After using the code above, you can use the same methods as for the daily currency rates.
|
63
78
|
|
64
|
-
CNB.
|
65
|
-
|
66
|
-
|
67
|
-
|
79
|
+
monthly_rates = CNB.monthly_rates(3, 2013)
|
80
|
+
monthly_rates.rate('HNL')
|
81
|
+
monthly_rates.name('HNL') # lempira
|
82
|
+
monthly_rates.country('HNL') # Honduras
|
83
|
+
monthly_rates.date
|
84
|
+
|
85
|
+
Get all currencies as hash
|
86
|
+
|
87
|
+
CNB.monthly_rates(3, 2013).currencies
|
68
88
|
|
69
89
|
|
70
90
|
### Primary currency
|
data/lib/cnb/currency_rates.rb
CHANGED
@@ -29,6 +29,8 @@ module CNB
|
|
29
29
|
|
30
30
|
def get_currencies
|
31
31
|
xml_doc = Nokogiri::XML(open(@cur_rates_url))
|
32
|
+
raise 'Currency rates are not available at the moment' if xml_doc.text.empty?
|
33
|
+
|
32
34
|
@date = Date.parse(xml_doc.css('kurzy').attr('datum').value)
|
33
35
|
|
34
36
|
xml_doc.css('radek').each do |currency|
|
data/lib/cnb/version.rb
CHANGED