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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8bebe99129e461c1bceb59a2a43f1754221488e
4
- data.tar.gz: 31d620b7020a35a9a82d692d51d7daa085864565
3
+ metadata.gz: 9351e3fb55843dc18b709b659c1e4ba66a2ff569
4
+ data.tar.gz: 24e90dc3a78adec9b85fd123753c9f3f213d00b9
5
5
  SHA512:
6
- metadata.gz: f7751cf538513923175f62e5321b306ea0d773dfdc9471be30e205e387c888e47212eb6e7196ec0e4ab53bda0359fc2a52928905a81b731da56b62d54e48e8b1
7
- data.tar.gz: f2a93574bb6034564afd3af9b657f39c888f0143b28471ba35f98f3f9a12aca08893ae45c69b6828100a6f2ebdae81f6099372a8f2849f330a6d9f979bcbf6f9
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 current currency rates start with the following code:
28
+ To work with daily currency rates start with the following code:
29
29
 
30
30
  CNB.daily_rates
31
31
 
32
- Get currency rate of currency towards czech crown (CZK) with given currency code
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
- CNB.rate('USD') # 19.927 (float value)
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
- Daily currency rates are used by default, so you can use the methods for getting rates, currency names and countries straight away.
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.rate('HNL')
65
- CNB.name('HNL') # lempira
66
- CNB.country('HNL') # Honduras
67
- CNB.date
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module CNB
2
- VERSION = '0.1.4'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Zikán