divISOr 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/divISOr.gemspec +5 -2
- data/lib/divISOr/divISOr.rb +33 -3
- data/lib/divISOr/hash_wrapper.rb +18 -0
- data/lib/divISOr/iso.rb +7 -0
- data/lib/divISOr/iso10383.rb +8 -2
- data/lib/divISOr/iso3166.rb +8 -2
- data/lib/divISOr/iso4217.rb +8 -2
- data/lib/divISOr/iso_data/10383 +246 -246
- data/lib/divISOr/iso_records.rb +6 -0
- data/lib/divISOr.rb +1 -0
- data/spec/divISOr/iso10383_spec.rb +23 -0
- data/spec/divISOr/iso3166_spec.rb +23 -1
- data/spec/divISOr/iso4217_spec.rb +52 -0
- data/spec/divISOr/iso_records_spec.rb +21 -0
- data/spec/divISOr_spec.rb +86 -6
- data/spec/iso_data/simple_data +1 -0
- metadata +7 -4
data/lib/divISOr/iso_records.rb
CHANGED
@@ -10,4 +10,10 @@ class ISORecords
|
|
10
10
|
fields = [fields] unless fields.is_a?(Array)
|
11
11
|
data.map{|record| fields.map{|field| record[field.to_sym] }}.flatten.compact.map(&:upcase)
|
12
12
|
end
|
13
|
+
|
14
|
+
def all(value, fields)
|
15
|
+
fields = [fields] unless fields.is_a?(Array)
|
16
|
+
return data if value.nil?
|
17
|
+
data.select{|record| fields.any?{|field| record[field] == value}}
|
18
|
+
end
|
13
19
|
end
|
data/lib/divISOr.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ISO10383 do
|
4
|
+
|
5
|
+
let(:data) { {:city=>"WARSZAWA", :acr=>"WSE", :code=>"XWAR", :country=>"POLAND", :description=>"WARSAW STOCK EXCHANGE", :currency=>"PL"} }
|
6
|
+
let(:different_data) {{:some => 'data'}}
|
7
|
+
let(:iso_10383) { ISO10383.new(data) }
|
8
|
+
|
9
|
+
it 'is equal to another ISO10383 object if contains the same data' do
|
10
|
+
same_iso_10383 = ISO10383.new(data)
|
11
|
+
different_iso_10383 = ISO10383.new(different_data)
|
12
|
+
iso_10383.should == same_iso_10383
|
13
|
+
iso_10383.should_not == different_iso_10383
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'responds to code' do
|
17
|
+
iso_10383.code.should == 'XWAR'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'responds to country' do
|
21
|
+
iso_10383.country.should == 'POLAND'
|
22
|
+
end
|
23
|
+
end
|
@@ -1,8 +1,30 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe ISO3166 do
|
4
|
+
|
5
|
+
let(:data) { {:code => "AD", :country => "ANDORRA"} }
|
6
|
+
let(:different_data) {{:some => 'data'}}
|
7
|
+
let(:iso_3166) { ISO3166.new(data) }
|
8
|
+
|
9
|
+
it 'is equal to another ISO3166 object if contains the same data' do
|
10
|
+
same_iso_3166 = ISO3166.new(data)
|
11
|
+
different_iso_3166 = ISO3166.new(different_data)
|
12
|
+
iso_3166.should == same_iso_3166
|
13
|
+
iso_3166.should_not == different_iso_3166
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'responds to code' do
|
17
|
+
iso_3166.code.should == 'AD'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'responds to country' do
|
21
|
+
iso_3166.country.should == 'ANDORRA'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ISO3166::Codes do
|
4
26
|
context 'validation' do
|
5
|
-
let(:iso_3166) {ISO3166.new}
|
27
|
+
let(:iso_3166) {ISO3166::Codes.new}
|
6
28
|
let(:iso_records) { mock(:values_for => ['US']) }
|
7
29
|
before { ISORecords.stub(:new => iso_records) }
|
8
30
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ISO4217 do
|
4
|
+
|
5
|
+
let(:data) { {:code => "AFN", :numeric_code => "971", :country => "AFGHANISTAN", :currency => "Afghani"} }
|
6
|
+
let(:different_data) {{:some => 'data'}}
|
7
|
+
let(:iso_4217) { ISO4217.new(data) }
|
8
|
+
|
9
|
+
it 'is equal to another ISO4217 object if contains the same data' do
|
10
|
+
same_iso_4217 = ISO4217.new(data)
|
11
|
+
different_iso_4217 = ISO4217.new(different_data)
|
12
|
+
iso_4217.should == same_iso_4217
|
13
|
+
iso_4217.should_not == different_iso_4217
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'responds to code' do
|
17
|
+
iso_4217.code.should == 'AFN'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'responds to numeric_code' do
|
21
|
+
iso_4217.numeric_code.should == '971'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'responds to country' do
|
25
|
+
iso_4217.country.should == 'AFGHANISTAN'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'responds to currency' do
|
29
|
+
iso_4217.currency.should == 'Afghani'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ISO4217::Codes do
|
34
|
+
context 'for simple data' do
|
35
|
+
let(:all_records) { [mock, mock] }
|
36
|
+
let(:iso_records) { mock(:all => all_records) }
|
37
|
+
before { ISORecords.stub(:new => iso_records) }
|
38
|
+
|
39
|
+
it 'gets all matching iso_record' do
|
40
|
+
iso_records.should_receive(:all).with('USD', :code)
|
41
|
+
ISO4217::Codes.new.all('USD') {|a| a == a }
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'builds objects from each record' do
|
45
|
+
all_records.each do |record|
|
46
|
+
ISO4217.should_receive(:new).with(record)
|
47
|
+
end
|
48
|
+
ISO4217::Codes.new.all('USD') {|a| ISO4217.new(a) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -8,6 +8,7 @@ describe ISORecords do
|
|
8
8
|
context 'on initialization' do
|
9
9
|
it 'loads data' do
|
10
10
|
iso_records.data.should == [{:code => 'A', :says => 'hello'},
|
11
|
+
{:country => 'A'},
|
11
12
|
{:code => 'B', :says => 'goodbye'}]
|
12
13
|
end
|
13
14
|
end
|
@@ -21,6 +22,25 @@ describe ISORecords do
|
|
21
22
|
iso_records.values_for([:code, :says]).should == ['A', 'HELLO', 'B', 'GOODBYE']
|
22
23
|
end
|
23
24
|
end
|
25
|
+
|
26
|
+
context 'retrieving all matching records' do
|
27
|
+
it 'for a single field with a single return value' do
|
28
|
+
iso_records.all('A', :code).should == [{:code => 'A', :says => 'hello'}]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'for multiple fields with a single return value' do
|
32
|
+
iso_records.all('A', [:says, :code]).should == [{:code => 'A', :says => 'hello'}]
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'for multiple fields with multple return values' do
|
36
|
+
iso_records.all('A', [:country, :code]).should == [{:code => 'A', :says => 'hello'}, {:country => 'A'}]
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'when called with a nil value' do
|
40
|
+
iso_records.all(nil, :code).should == [{:code => 'A', :says => 'hello'}, {:country => 'A'},
|
41
|
+
{:code => 'B', :says => 'goodbye'}]
|
42
|
+
end
|
43
|
+
end
|
24
44
|
end
|
25
45
|
|
26
46
|
context 'for complex data' do
|
@@ -47,5 +67,6 @@ describe ISORecords do
|
|
47
67
|
end
|
48
68
|
end
|
49
69
|
end
|
70
|
+
|
50
71
|
end
|
51
72
|
|
data/spec/divISOr_spec.rb
CHANGED
@@ -4,10 +4,10 @@ describe "Divisor" do
|
|
4
4
|
context 'validation' do
|
5
5
|
context 'for ISO 3166' do
|
6
6
|
let(:iso3166) { mock(:validate => true) }
|
7
|
-
before { ISO3166.stub(:new => iso3166) }
|
7
|
+
before { ISO3166::Codes.stub(:new => iso3166) }
|
8
8
|
|
9
9
|
it 'create a ISO3166 on first call' do
|
10
|
-
ISO3166.should_receive(:new)
|
10
|
+
ISO3166::Codes.should_receive(:new)
|
11
11
|
DivISOr.validate_iso3166('US')
|
12
12
|
end
|
13
13
|
|
@@ -24,10 +24,10 @@ describe "Divisor" do
|
|
24
24
|
|
25
25
|
context 'for ISO 4217' do
|
26
26
|
let(:iso4217) { mock(:validate => true) }
|
27
|
-
before { ISO4217.stub(:new => iso4217) }
|
27
|
+
before { ISO4217::Codes.stub(:new => iso4217) }
|
28
28
|
|
29
29
|
it 'create a ISO4217 on first call' do
|
30
|
-
ISO4217.should_receive(:new)
|
30
|
+
ISO4217::Codes.should_receive(:new)
|
31
31
|
DivISOr.validate_iso4217('USD')
|
32
32
|
end
|
33
33
|
|
@@ -44,10 +44,10 @@ describe "Divisor" do
|
|
44
44
|
|
45
45
|
context 'for ISO 10383' do
|
46
46
|
let(:iso10383) { mock(:validate => true) }
|
47
|
-
before { ISO10383.stub(:new => iso10383) }
|
47
|
+
before { ISO10383::Codes.stub(:new => iso10383) }
|
48
48
|
|
49
49
|
it 'create a ISO10383 on first call' do
|
50
|
-
ISO10383.should_receive(:new)
|
50
|
+
ISO10383::Codes.should_receive(:new)
|
51
51
|
DivISOr.validate_iso10383('BARX')
|
52
52
|
end
|
53
53
|
|
@@ -62,4 +62,84 @@ describe "Divisor" do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
|
+
|
66
|
+
context 'lookup' do
|
67
|
+
context 'for ISO 4217' do
|
68
|
+
let(:iso4217) { mock(:validate => true) }
|
69
|
+
before { ISO4217::Codes.stub(:new => iso4217) }
|
70
|
+
|
71
|
+
it 'gets all records' do
|
72
|
+
iso4217.should_receive(:all).with('USD')
|
73
|
+
DivISOr.iso4217('USD')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'for ISO 3166' do
|
78
|
+
let(:all_records) { mock(:first => false) }
|
79
|
+
let(:iso3166) { mock(:validate => true, :all => all_records) }
|
80
|
+
before { ISO3166::Codes.stub(:new => iso3166) }
|
81
|
+
|
82
|
+
it 'gets all records' do
|
83
|
+
iso3166.should_receive(:all).with('US')
|
84
|
+
DivISOr.iso3166('US')
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'gets the first record' do
|
88
|
+
all_records.should_receive(:first)
|
89
|
+
DivISOr.iso3166('US')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'for ISO 10383' do
|
94
|
+
let(:all_records) { mock(:first => false) }
|
95
|
+
let(:iso10383) { mock(:validate => true, :all => all_records) }
|
96
|
+
before { ISO10383::Codes.stub(:new => iso10383) }
|
97
|
+
|
98
|
+
it 'gets all records' do
|
99
|
+
iso10383.should_receive(:all).with('US')
|
100
|
+
DivISOr.iso10383('US')
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'gets the first record' do
|
104
|
+
all_records.should_receive(:first)
|
105
|
+
DivISOr.iso10383('US')
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'list all records' do
|
111
|
+
context 'for ISO 4217' do
|
112
|
+
let(:all_records) { mock }
|
113
|
+
let(:iso4217) { mock(:validate => true, :all => all_records) }
|
114
|
+
before { ISO4217::Codes.stub(:new => iso4217) }
|
115
|
+
|
116
|
+
it 'gets all records' do
|
117
|
+
iso4217.should_receive(:all).with(nil)
|
118
|
+
DivISOr.list_iso4217.should == all_records
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'for ISO 3166' do
|
123
|
+
let(:all_records) { mock }
|
124
|
+
let(:iso3166) { mock(:validate => true, :all => all_records) }
|
125
|
+
before { ISO3166::Codes.stub(:new => iso3166) }
|
126
|
+
|
127
|
+
it 'gets all records' do
|
128
|
+
iso3166.should_receive(:all).with(nil)
|
129
|
+
DivISOr.list_iso3166.should == all_records
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'for ISO 10383' do
|
134
|
+
let(:all_records) { mock }
|
135
|
+
let(:iso10383) { mock(:validate => true, :all => all_records) }
|
136
|
+
before { ISO10383::Codes.stub(:new => iso10383) }
|
137
|
+
|
138
|
+
it 'gets all records' do
|
139
|
+
iso10383.should_receive(:all).with(nil)
|
140
|
+
DivISOr.list_iso10383.should == all_records
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
65
144
|
end
|
145
|
+
|
data/spec/iso_data/simple_data
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: divISOr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.1
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "David Henry and Alberto Pe\xC3\xB1a"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-29 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- divISOr.gemspec
|
131
131
|
- lib/divISOr.rb
|
132
132
|
- lib/divISOr/divISOr.rb
|
133
|
+
- lib/divISOr/hash_wrapper.rb
|
133
134
|
- lib/divISOr/iso.rb
|
134
135
|
- lib/divISOr/iso10383.rb
|
135
136
|
- lib/divISOr/iso3166.rb
|
@@ -138,7 +139,9 @@ files:
|
|
138
139
|
- lib/divISOr/iso_data/3166
|
139
140
|
- lib/divISOr/iso_data/4217
|
140
141
|
- lib/divISOr/iso_records.rb
|
142
|
+
- spec/divISOr/iso10383_spec.rb
|
141
143
|
- spec/divISOr/iso3166_spec.rb
|
144
|
+
- spec/divISOr/iso4217_spec.rb
|
142
145
|
- spec/divISOr/iso_records_spec.rb
|
143
146
|
- spec/divISOr_spec.rb
|
144
147
|
- spec/iso_data/complex_data
|