cnb 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/lib/cnb/currency_rates.rb +1 -1
- data/lib/cnb/monthly_rates.rb +2 -2
- data/lib/cnb/version.rb +1 -1
- data/lib/cnb.rb +6 -24
- data/spec/cnb_spec.rb +34 -0
- data/spec/spec_helper.rb +1 -3
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b1981ee623b1b196bac0e1fa96e15c1278d1197
|
4
|
+
data.tar.gz: 8ea6a41b478a5d94feb0fb0a8d832a01e1cd8d12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ebd88e00c2b4d9ae38f9d552adffe22f711365f090d5cdd0f3b9558af2335fcf0cef9d84f308acf22a117f0573e189110f1ff31e2af8f89b0fb6790ea26358d
|
7
|
+
data.tar.gz: 8740aaad851c8f7dc669e16d6520e0f1213b09e5d4aceff1d907c89469e506044f4913e3b99ad5aab6e36cf7806e0024e10d879b29fec7cc20e67b2c5980e5d1
|
data/lib/cnb/currency_rates.rb
CHANGED
data/lib/cnb/monthly_rates.rb
CHANGED
@@ -4,8 +4,8 @@ module CNB
|
|
4
4
|
@month = month
|
5
5
|
@year = year
|
6
6
|
|
7
|
-
raise 'Invalid
|
8
|
-
raise 'Invalid
|
7
|
+
raise 'Invalid month given' unless valid_month?
|
8
|
+
raise 'Invalid year given' unless valid_year?
|
9
9
|
|
10
10
|
@currencies = {}
|
11
11
|
@cur_rates_url = "#{CUR_RATES_URL}/kurzy_ostatnich_men/kurzy.xml?mesic=#{month}&rok=#{year}"
|
data/lib/cnb/version.rb
CHANGED
data/lib/cnb.rb
CHANGED
@@ -5,35 +5,17 @@ require_relative 'cnb/monthly_rates'
|
|
5
5
|
module CNB
|
6
6
|
PRIMARY_CURRENCY = 'CZK'
|
7
7
|
|
8
|
+
@rates_objects = {}
|
9
|
+
|
8
10
|
class << self
|
9
11
|
def daily_rates
|
10
|
-
|
12
|
+
key = :daily
|
13
|
+
@rates_objects[key] ||= DailyRates.new
|
11
14
|
end
|
12
15
|
|
13
16
|
def monthly_rates(month, year)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
def date
|
18
|
-
parser.date
|
19
|
-
end
|
20
|
-
|
21
|
-
def rate(cur_code)
|
22
|
-
parser.rate(cur_code)
|
23
|
-
end
|
24
|
-
|
25
|
-
def name(cur_code)
|
26
|
-
parser.name(cur_code)
|
27
|
-
end
|
28
|
-
|
29
|
-
def country(cur_code)
|
30
|
-
parser.country(cur_code)
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def parser
|
36
|
-
@parser ||= DailyRates.new
|
17
|
+
key = "#{month}-#{year}"
|
18
|
+
@rates_objects[key] ||= MonthlyRates.new(month, year)
|
37
19
|
end
|
38
20
|
end
|
39
21
|
end
|
data/spec/cnb_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'CNB' do
|
4
|
+
describe '#daily_rates' do
|
5
|
+
before(:each) do
|
6
|
+
CNB::DailyRates.any_instance.stub(:get_currencies) { {} }
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns DailyRates object' do
|
10
|
+
expect(CNB.daily_rates).to be_a(CNB::DailyRates)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'always returns the same object' do
|
14
|
+
rates = CNB.daily_rates
|
15
|
+
expect(CNB.daily_rates.object_id).to eq rates.object_id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#monthly_rates' do
|
20
|
+
before(:each) do
|
21
|
+
CNB::MonthlyRates.any_instance.stub(:get_currencies) { {} }
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns MonthlyRates object' do
|
25
|
+
expect(CNB.monthly_rates(11,2013)).to be_a(CNB::MonthlyRates)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'always returns the same object for the same combination of month and year params' do
|
29
|
+
rates = CNB.monthly_rates(11, 2013)
|
30
|
+
expect(CNB.monthly_rates(11, 2013).object_id).to eq rates.object_id
|
31
|
+
expect(CNB.monthly_rates(10, 2013).object_id).not_to eq rates.object_id
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,9 +6,7 @@ if ENV['COVERAGE']
|
|
6
6
|
SimpleCov.start
|
7
7
|
end
|
8
8
|
|
9
|
-
require 'cnb
|
10
|
-
require 'cnb/daily_rates'
|
11
|
-
require 'cnb/monthly_rates'
|
9
|
+
require 'cnb'
|
12
10
|
|
13
11
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
14
12
|
# in spec/support/ and its subdirectories.
|
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
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Zikán
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/cnb/daily_rates.rb
|
100
100
|
- lib/cnb/monthly_rates.rb
|
101
101
|
- lib/cnb/version.rb
|
102
|
+
- spec/cnb_spec.rb
|
102
103
|
- spec/fixtures/daily_rates.xml
|
103
104
|
- spec/fixtures/monthly_rates_2013_03.xml
|
104
105
|
- spec/models/daily_rates_spec.rb
|