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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1fc9b6106a803a576a97a106bb7f4b3d20bbd99
4
- data.tar.gz: 8ea44b922132d9bc5c0df125ff80972ff3cef254
3
+ metadata.gz: 1b1981ee623b1b196bac0e1fa96e15c1278d1197
4
+ data.tar.gz: 8ea6a41b478a5d94feb0fb0a8d832a01e1cd8d12
5
5
  SHA512:
6
- metadata.gz: cc4fe3b8ea2849295b18e1371282fe1574869fa6e8223820ed8299c72391de7a0f0d48092a6c21a698ee9a9faea80a627892ee21404ba16e896a5d9da53c851c
7
- data.tar.gz: 2f19c1e0d98fe58fd06713f406f29dcd3c78553cdce1cee5841a3d41d20e7cfc87ca8d34f6389457527976553b7be417d7a971be077b791e09c44b5a02c9836b
6
+ metadata.gz: 4ebd88e00c2b4d9ae38f9d552adffe22f711365f090d5cdd0f3b9558af2335fcf0cef9d84f308acf22a117f0573e189110f1ff31e2af8f89b0fb6790ea26358d
7
+ data.tar.gz: 8740aaad851c8f7dc669e16d6520e0f1213b09e5d4aceff1d907c89469e506044f4913e3b99ad5aab6e36cf7806e0024e10d879b29fec7cc20e67b2c5980e5d1
@@ -5,7 +5,7 @@ module CNB
5
5
  class CurrencyRates
6
6
  CUR_RATES_URL = 'http://www.cnb.cz/cs/financni_trhy/devizovy_trh/'
7
7
 
8
- attr_reader :cur_rates_filepath, :date
8
+ attr_reader :date, :currencies
9
9
 
10
10
  def rate(cur_code)
11
11
  get_currency(cur_code)[:rate]
@@ -4,8 +4,8 @@ module CNB
4
4
  @month = month
5
5
  @year = year
6
6
 
7
- raise 'Invalid year given' unless valid_month?
8
- raise 'Invalid month given' unless valid_year?
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
@@ -1,3 +1,3 @@
1
1
  module CNB
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
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
- @parser = DailyRates.new
12
+ key = :daily
13
+ @rates_objects[key] ||= DailyRates.new
11
14
  end
12
15
 
13
16
  def monthly_rates(month, year)
14
- @parser = MonthlyRates.new(month, year)
15
- end
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/currency_rates'
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.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