divISOr 0.0.1
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.
- data/.document +5 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/divISOr.gemspec +80 -0
- data/lib/divISOr/divISOr.rb +14 -0
- data/lib/divISOr/iso.rb +20 -0
- data/lib/divISOr/iso10383.rb +5 -0
- data/lib/divISOr/iso3166.rb +4 -0
- data/lib/divISOr/iso4217.rb +4 -0
- data/lib/divISOr/iso_data/10383 +716 -0
- data/lib/divISOr/iso_data/3166 +246 -0
- data/lib/divISOr/iso_data/4217 +290 -0
- data/lib/divISOr/iso_records.rb +13 -0
- data/lib/divISOr.rb +9 -0
- data/spec/divISOr/iso3166_spec.rb +45 -0
- data/spec/divISOr/iso_records_spec.rb +51 -0
- data/spec/divISOr_spec.rb +65 -0
- data/spec/iso_data/complex_data +5 -0
- data/spec/iso_data/simple_data +5 -0
- data/spec/spec_helper.rb +12 -0
- metadata +182 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ISO3166 do
|
4
|
+
context 'validation' do
|
5
|
+
let(:iso_3166) {ISO3166.new}
|
6
|
+
let(:iso_records) { mock(:values_for => ['US']) }
|
7
|
+
before { ISORecords.stub(:new => iso_records) }
|
8
|
+
|
9
|
+
context 'on default field' do
|
10
|
+
it 'gets a list of values' do
|
11
|
+
iso_records.should_receive(:values_for).with(:code)
|
12
|
+
iso_3166.validate('US')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'on country field' do
|
17
|
+
it 'gets a list of values' do
|
18
|
+
iso_records.should_receive(:values_for).with(:country)
|
19
|
+
iso_3166.validate('2345', :country)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'on multiple fields' do
|
24
|
+
it 'gets a list of values' do
|
25
|
+
iso_records.should_receive(:values_for).with([:code, :country])
|
26
|
+
iso_3166.validate('1234', [:code, :country])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'returns true if the value is valid' do
|
31
|
+
it 'with matching case' do
|
32
|
+
iso_3166.validate('us').should be_true
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'with different case' do
|
36
|
+
iso_3166.validate('US').should be_true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns false if the value is invalid' do
|
41
|
+
iso_records.stub(:values_for => [])
|
42
|
+
iso_3166.validate('BLABLA').should be_false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ISORecords do
|
4
|
+
|
5
|
+
context 'for simple data' do
|
6
|
+
let(:iso_records) { ISORecords.new(File.expand_path(File.dirname(__FILE__) + '/../iso_data/simple_data')) }
|
7
|
+
|
8
|
+
context 'on initialization' do
|
9
|
+
it 'loads data' do
|
10
|
+
iso_records.data.should == [{:code => 'A', :says => 'hello'},
|
11
|
+
{:code => 'B', :says => 'goodbye'}]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'returns values when' do
|
16
|
+
it 'filtered by a field' do
|
17
|
+
iso_records.values_for(:says).should == ['HELLO', 'GOODBYE']
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'filtered by multiple fields' do
|
21
|
+
iso_records.values_for([:code, :says]).should == ['A', 'HELLO', 'B', 'GOODBYE']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'for complex data' do
|
27
|
+
let(:iso_records) { ISORecords.new(File.expand_path(File.dirname(__FILE__) + '/../iso_data/complex_data')) }
|
28
|
+
|
29
|
+
context 'on initialization' do
|
30
|
+
it 'loads data' do
|
31
|
+
iso_records.data.should == [{:code => 'A', :entity => ['Alpha', 'Beta'], :says => 'hello'},
|
32
|
+
{:code => 'B', :says => 'goodbye'}]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'returns values when' do
|
37
|
+
it 'filtered by a field' do
|
38
|
+
iso_records.values_for(:entity).should == ['ALPHA', 'BETA']
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'filtered by a string field' do
|
42
|
+
iso_records.values_for("entity").should == ['ALPHA', 'BETA']
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'filtered by multiple fields' do
|
46
|
+
iso_records.values_for([:entity, :says]).should == ['ALPHA', 'BETA', 'HELLO', 'GOODBYE']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Divisor" do
|
4
|
+
context 'validation' do
|
5
|
+
context 'for ISO 3166' do
|
6
|
+
let(:iso3166) { mock(:validate => true) }
|
7
|
+
before { ISO3166.stub(:new => iso3166) }
|
8
|
+
|
9
|
+
it 'create a ISO3166 on first call' do
|
10
|
+
ISO3166.should_receive(:new)
|
11
|
+
DivISOr.validate_iso3166('US')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'delegates to the ISO3166 class' do
|
15
|
+
iso3166.should_receive(:validate).with('US')
|
16
|
+
DivISOr.validate_iso3166('US')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'takes an optional 2nd variable' do
|
20
|
+
iso3166.should_receive(:validate).with('US', :code)
|
21
|
+
DivISOr.validate_iso3166('US', :code)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'for ISO 4217' do
|
26
|
+
let(:iso4217) { mock(:validate => true) }
|
27
|
+
before { ISO4217.stub(:new => iso4217) }
|
28
|
+
|
29
|
+
it 'create a ISO4217 on first call' do
|
30
|
+
ISO4217.should_receive(:new)
|
31
|
+
DivISOr.validate_iso4217('USD')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'delegates to the ISO4217 class' do
|
35
|
+
iso4217.should_receive(:validate).with('USD')
|
36
|
+
DivISOr.validate_iso4217('USD')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'takes an optional 2nd variable' do
|
40
|
+
iso4217.should_receive(:validate).with('USD', :code)
|
41
|
+
DivISOr.validate_iso4217('USD', :code)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'for ISO 10383' do
|
46
|
+
let(:iso10383) { mock(:validate => true) }
|
47
|
+
before { ISO10383.stub(:new => iso10383) }
|
48
|
+
|
49
|
+
it 'create a ISO10383 on first call' do
|
50
|
+
ISO10383.should_receive(:new)
|
51
|
+
DivISOr.validate_iso10383('BARX')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'delegates to the ISO10383 class' do
|
55
|
+
iso10383.should_receive(:validate).with('BARX')
|
56
|
+
DivISOr.validate_iso10383('BARX')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'takes an optional 2nd variable' do
|
60
|
+
iso10383.should_receive(:validate).with('BARX', :code)
|
61
|
+
DivISOr.validate_iso10383('BARX', :code)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'divISOr'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: divISOr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "David Henry and Alberto Pe\xC3\xB1a"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-28 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
name: json
|
33
|
+
version_requirements: *id001
|
34
|
+
prerelease: false
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
type: :development
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
- 3
|
46
|
+
- 0
|
47
|
+
version: 2.3.0
|
48
|
+
name: rspec
|
49
|
+
version_requirements: *id002
|
50
|
+
prerelease: false
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
type: :development
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 23
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 0
|
62
|
+
- 0
|
63
|
+
version: 1.0.0
|
64
|
+
name: bundler
|
65
|
+
version_requirements: *id003
|
66
|
+
prerelease: false
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
type: :development
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 11
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 6
|
78
|
+
- 2
|
79
|
+
version: 1.6.2
|
80
|
+
name: jeweler
|
81
|
+
version_requirements: *id004
|
82
|
+
prerelease: false
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
type: :development
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
name: rcov
|
95
|
+
version_requirements: *id005
|
96
|
+
prerelease: false
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
type: :development
|
99
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
name: ruby-debug
|
109
|
+
version_requirements: *id006
|
110
|
+
prerelease: false
|
111
|
+
description: Validate and look up functionality for ISO standards
|
112
|
+
email: dave_henry@lyagushka.co.uk
|
113
|
+
executables: []
|
114
|
+
|
115
|
+
extensions: []
|
116
|
+
|
117
|
+
extra_rdoc_files:
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.rdoc
|
120
|
+
files:
|
121
|
+
- .document
|
122
|
+
- .rspec
|
123
|
+
- .rvmrc
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.rdoc
|
128
|
+
- Rakefile
|
129
|
+
- VERSION
|
130
|
+
- divISOr.gemspec
|
131
|
+
- lib/divISOr.rb
|
132
|
+
- lib/divISOr/divISOr.rb
|
133
|
+
- lib/divISOr/iso.rb
|
134
|
+
- lib/divISOr/iso10383.rb
|
135
|
+
- lib/divISOr/iso3166.rb
|
136
|
+
- lib/divISOr/iso4217.rb
|
137
|
+
- lib/divISOr/iso_data/10383
|
138
|
+
- lib/divISOr/iso_data/3166
|
139
|
+
- lib/divISOr/iso_data/4217
|
140
|
+
- lib/divISOr/iso_records.rb
|
141
|
+
- spec/divISOr/iso3166_spec.rb
|
142
|
+
- spec/divISOr/iso_records_spec.rb
|
143
|
+
- spec/divISOr_spec.rb
|
144
|
+
- spec/iso_data/complex_data
|
145
|
+
- spec/iso_data/simple_data
|
146
|
+
- spec/spec_helper.rb
|
147
|
+
has_rdoc: true
|
148
|
+
homepage: http://github.com/LyagushkaLimited/divISOr
|
149
|
+
licenses:
|
150
|
+
- MIT
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
hash: 3
|
162
|
+
segments:
|
163
|
+
- 0
|
164
|
+
version: "0"
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
none: false
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
hash: 3
|
171
|
+
segments:
|
172
|
+
- 0
|
173
|
+
version: "0"
|
174
|
+
requirements: []
|
175
|
+
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 1.5.3
|
178
|
+
signing_key:
|
179
|
+
specification_version: 3
|
180
|
+
summary: Validate and look up functionality for ISO standards
|
181
|
+
test_files: []
|
182
|
+
|