ibandit 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ibandit::PseudoIBANAssembler do
4
+ subject(:pseudo_iban) { described_class.new(local_details).assemble }
5
+
6
+ context 'for Sweden' do
7
+ context 'with valid parameters' do
8
+ let(:local_details) do
9
+ {
10
+ country_code: 'SE',
11
+ branch_code: '1281',
12
+ account_number: '0105723'
13
+ }
14
+ end
15
+
16
+ it { is_expected.to eq('SEZZX1281XXX0105723') }
17
+ end
18
+
19
+ context 'without a branch code' do
20
+ let(:local_details) do
21
+ {
22
+ country_code: 'SE',
23
+ account_number: '0105723'
24
+ }
25
+ end
26
+
27
+ it { is_expected.to be_nil }
28
+ end
29
+
30
+ context 'without an account number' do
31
+ let(:local_details) do
32
+ {
33
+ country_code: 'SE',
34
+ branch_code: '1281'
35
+ }
36
+ end
37
+
38
+ it { is_expected.to be_nil }
39
+ end
40
+ end
41
+
42
+ context 'for a country that does not have pseudo-IBANs' do
43
+ let(:local_details) do
44
+ {
45
+ country_code: 'GB',
46
+ bank_code: 'WEST',
47
+ branch_code: '123456',
48
+ account_number: '98765432'
49
+ }
50
+ end
51
+
52
+ it { is_expected.to be_nil }
53
+ end
54
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ibandit::PseudoIBANSplitter do
4
+ subject(:splitter) { described_class.new(pseudo_iban) }
5
+
6
+ describe '#split' do
7
+ subject(:local_details) { splitter.split }
8
+
9
+ context 'for a valid pseudo-IBAN' do
10
+ let(:pseudo_iban) { 'SEZZX1281XXX0105723' }
11
+
12
+ its([:country_code]) { is_expected.to eq('SE') }
13
+ its([:bank_code]) { is_expected.to be_nil }
14
+ its([:branch_code]) { is_expected.to eq('1281') }
15
+ its([:account_number]) { is_expected.to eq('0105723') }
16
+ end
17
+
18
+ context 'for an unsupported country' do
19
+ let(:pseudo_iban) { 'GBZZX1281XXX0105723' }
20
+
21
+ it { is_expected.to be_nil }
22
+ end
23
+
24
+ context 'with invalid check digits' do
25
+ let(:pseudo_iban) { 'SEYYX1281XXX0105723' }
26
+
27
+ it { is_expected.to be_nil }
28
+ end
29
+
30
+ context 'with the wrong length' do
31
+ let(:pseudo_iban) { 'SEYYX1281XXX010572' }
32
+
33
+ it { is_expected.to be_nil }
34
+ end
35
+ end
36
+ end
@@ -1,133 +1,208 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ibandit::SwedishDetailsConverter do
4
+ subject(:converter) do
5
+ described_class.new(account_number: account_number,
6
+ branch_code: branch_code)
7
+ end
8
+
9
+ let(:branch_code) { nil }
10
+
4
11
  describe '.convert' do
5
- subject { described_class.convert(account_number) }
12
+ subject { converter.convert }
6
13
 
7
14
  context 'with a type-1 account number' do
8
15
  let(:account_number) { '12810105723' }
9
16
 
10
- its([:bank_code]) { is_expected.to eq('120') }
11
- its([:account_number]) { is_expected.to eq('00000012810105723') }
17
+ its([:account_number]) { is_expected.to eq('0105723') }
18
+ its([:branch_code]) { is_expected.to eq('1281') }
19
+ its([:swift_bank_code]) { is_expected.to eq('120') }
20
+ its([:swift_account_number]) { is_expected.to eq('00000012810105723') }
12
21
 
13
22
  context 'that includes hyphens' do
14
23
  let(:account_number) { '1281-0105723' }
15
24
 
16
- its([:bank_code]) { is_expected.to eq('120') }
17
- its([:account_number]) { is_expected.to eq('00000012810105723') }
25
+ its([:account_number]) { is_expected.to eq('0105723') }
26
+ its([:branch_code]) { is_expected.to eq('1281') }
27
+ its([:swift_bank_code]) { is_expected.to eq('120') }
28
+ its([:swift_account_number]) { is_expected.to eq('00000012810105723') }
29
+ end
30
+
31
+ context 'with a separate branch code' do
32
+ let(:branch_code) { '1281' }
33
+ let(:account_number) { '0105723' }
34
+
35
+ its([:account_number]) { is_expected.to eq('0105723') }
36
+ its([:branch_code]) { is_expected.to eq('1281') }
37
+ its([:swift_bank_code]) { is_expected.to eq('120') }
38
+ its([:swift_account_number]) { is_expected.to eq('00000012810105723') }
18
39
  end
19
40
 
20
41
  context 'that includes spaces' do
21
42
  let(:account_number) { '1281 0105723' }
22
43
 
23
- its([:bank_code]) { is_expected.to eq('120') }
24
- its([:account_number]) { is_expected.to eq('00000012810105723') }
44
+ its([:account_number]) { is_expected.to eq('0105723') }
45
+ its([:branch_code]) { is_expected.to eq('1281') }
46
+ its([:swift_bank_code]) { is_expected.to eq('120') }
47
+ its([:swift_account_number]) { is_expected.to eq('00000012810105723') }
25
48
  end
26
49
 
27
50
  context 'that includes full stops' do
28
51
  let(:account_number) { '1281.010.572.3' }
29
52
 
30
- its([:bank_code]) { is_expected.to eq('120') }
31
- its([:account_number]) { is_expected.to eq('00000012810105723') }
53
+ its([:account_number]) { is_expected.to eq('0105723') }
54
+ its([:branch_code]) { is_expected.to eq('1281') }
55
+ its([:swift_bank_code]) { is_expected.to eq('120') }
56
+ its([:swift_account_number]) { is_expected.to eq('00000012810105723') }
32
57
  end
33
58
 
34
59
  context 'that has been zero-padded' do
35
60
  let(:account_number) { '000012810105723' }
36
61
 
37
- its([:bank_code]) { is_expected.to eq('120') }
38
- its([:account_number]) { is_expected.to eq('00000012810105723') }
62
+ its([:account_number]) { is_expected.to eq('0105723') }
63
+ its([:branch_code]) { is_expected.to eq('1281') }
64
+ its([:swift_bank_code]) { is_expected.to eq('120') }
65
+ its([:swift_account_number]) { is_expected.to eq('00000012810105723') }
39
66
  end
40
67
 
41
68
  context 'that needs the account number part to be zero-padded' do
42
69
  let(:account_number) { '1281-1' }
43
70
 
44
- its([:bank_code]) { is_expected.to eq('120') }
45
- its([:account_number]) { is_expected.to eq('00000000000012811') }
71
+ its([:account_number]) { is_expected.to eq('1') }
72
+ its([:branch_code]) { is_expected.to eq('1281') }
73
+ its([:swift_bank_code]) { is_expected.to eq('120') }
74
+ its([:swift_account_number]) { is_expected.to eq('00000000000012811') }
46
75
  end
47
76
 
48
77
  context 'from SEB' do
49
78
  let(:account_number) { '5439-10 240 39' }
50
79
 
51
- its([:bank_code]) { is_expected.to eq('500') }
52
- its([:account_number]) { is_expected.to eq('00000054391024039') }
80
+ its([:account_number]) { is_expected.to eq('1024039') }
81
+ its([:branch_code]) { is_expected.to eq('5439') }
82
+ its([:swift_bank_code]) { is_expected.to eq('500') }
83
+ its([:swift_account_number]) { is_expected.to eq('00000054391024039') }
84
+
85
+ context 'with a separate branch code' do
86
+ let(:branch_code) { '5439' }
87
+ let(:account_number) { '1024039' }
88
+
89
+ its([:account_number]) { is_expected.to eq('1024039') }
90
+ its([:branch_code]) { is_expected.to eq('5439') }
91
+ its([:swift_bank_code]) { is_expected.to eq('500') }
92
+ its([:swift_account_number]) do
93
+ is_expected.to eq('00000054391024039')
94
+ end
95
+ end
53
96
  end
54
97
  end
55
98
 
56
99
  context "with a clearing code that doesn't match any banks" do
57
100
  let(:account_number) { '1001-1' }
58
101
 
59
- its([:bank_code]) { is_expected.to eq(nil) }
60
- its([:account_number]) { is_expected.to eq('00000000000010011') }
102
+ its([:account_number]) { is_expected.to eq(nil) }
103
+ its([:branch_code]) { is_expected.to eq(nil) }
104
+ its([:swift_bank_code]) { is_expected.to eq(nil) }
105
+ its([:swift_account_number]) { is_expected.to eq('00000000000010011') }
61
106
  end
62
107
 
63
108
  context 'with a Swedbank clearing code' do
64
109
  let(:account_number) { '7507-1211203' }
65
110
 
66
- its([:bank_code]) { is_expected.to eq('800') }
67
- its([:account_number]) { is_expected.to eq('00000075071211203') }
111
+ its([:account_number]) { is_expected.to eq('1211203') }
112
+ its([:branch_code]) { is_expected.to eq('7507') }
113
+ its([:swift_bank_code]) { is_expected.to eq('800') }
114
+ its([:swift_account_number]) { is_expected.to eq('00000075071211203') }
68
115
 
69
116
  context 'in the 8000s range' do
70
117
  let(:account_number) { '8327-9 33395390-9' }
71
118
 
72
- its([:bank_code]) { is_expected.to eq('800') }
73
- its([:account_number]) { is_expected.to eq('00832790333953909') }
119
+ its([:account_number]) { is_expected.to eq('0333953909') }
120
+ its([:branch_code]) { is_expected.to eq('83279') }
121
+ its([:swift_bank_code]) { is_expected.to eq('800') }
122
+ its([:swift_account_number]) { is_expected.to eq('00832790333953909') }
74
123
  end
75
124
 
76
125
  context 'another in the 8000s range' do
77
126
  let(:account_number) { '8201-6 914357963-0' }
78
127
 
79
- its([:bank_code]) { is_expected.to eq('800') }
80
- its([:account_number]) { is_expected.to eq('00820169143579630') }
128
+ its([:account_number]) { is_expected.to eq('9143579630') }
129
+ its([:branch_code]) { is_expected.to eq('82016') }
130
+ its([:swift_bank_code]) { is_expected.to eq('800') }
131
+ its([:swift_account_number]) { is_expected.to eq('00820169143579630') }
132
+ end
133
+
134
+ context 'with an explicit branch code' do
135
+ let(:branch_code) { '8201-6' }
136
+ let(:account_number) { '914357963-0' }
137
+
138
+ its([:account_number]) { is_expected.to eq('9143579630') }
139
+ its([:branch_code]) { is_expected.to eq('82016') }
140
+ its([:swift_bank_code]) { is_expected.to eq('800') }
141
+ its([:swift_account_number]) { is_expected.to eq('00820169143579630') }
81
142
  end
82
143
  end
83
144
 
84
145
  context 'with a Sparbanken Öresund clearing code' do
85
146
  let(:account_number) { '9300-35299478' }
86
147
 
87
- its([:bank_code]) { is_expected.to eq('930') }
88
- its([:account_number]) { is_expected.to eq('00000000035299478') }
148
+ its([:account_number]) { is_expected.to eq('35299478') }
149
+ its([:branch_code]) { is_expected.to eq('9300') }
150
+ its([:swift_bank_code]) { is_expected.to eq('930') }
151
+ its([:swift_account_number]) { is_expected.to eq('00000000035299478') }
89
152
 
90
153
  context 'with clearing number 9330 or above' do
91
154
  let(:account_number) { '9330-5930160535' }
92
155
 
93
- its([:bank_code]) { is_expected.to eq('933') }
94
- its([:account_number]) { is_expected.to eq('00000005930160535') }
156
+ its([:account_number]) { is_expected.to eq('5930160535') }
157
+ its([:branch_code]) { is_expected.to eq('9330') }
158
+ its([:swift_bank_code]) { is_expected.to eq('933') }
159
+ its([:swift_account_number]) { is_expected.to eq('00000005930160535') }
95
160
  end
96
161
  end
97
162
 
98
163
  context 'with a Sparbanken Syd clearing code' do
99
164
  let(:account_number) { '9570-5250093407' }
100
165
 
101
- its([:bank_code]) { is_expected.to eq('957') }
102
- its([:account_number]) { is_expected.to eq('00000005250093407') }
166
+ its([:account_number]) { is_expected.to eq('5250093407') }
167
+ its([:branch_code]) { is_expected.to eq('9570') }
168
+ its([:swift_bank_code]) { is_expected.to eq('957') }
169
+ its([:swift_account_number]) { is_expected.to eq('00000005250093407') }
103
170
  end
104
171
 
105
172
  context 'with a Handelsbanken clearing code' do
106
173
  let(:account_number) { '6000-806967498' }
107
174
 
108
- its([:bank_code]) { is_expected.to eq('600') }
109
- its([:account_number]) { is_expected.to eq('00000000806967498') }
175
+ its([:account_number]) { is_expected.to eq('806967498') }
176
+ its([:branch_code]) { is_expected.to eq('6000') }
177
+ its([:swift_bank_code]) { is_expected.to eq('600') }
178
+ its([:swift_account_number]) { is_expected.to eq('00000000806967498') }
110
179
 
111
180
  context 'that has clearing code 6240' do
112
181
  let(:account_number) { '6240-219161038' }
113
182
 
114
- its([:bank_code]) { is_expected.to eq('600') }
115
- its([:account_number]) { is_expected.to eq('00000000219161038') }
183
+ its([:account_number]) { is_expected.to eq('219161038') }
184
+ its([:branch_code]) { is_expected.to eq('6240') }
185
+ its([:swift_bank_code]) { is_expected.to eq('600') }
186
+ its([:swift_account_number]) { is_expected.to eq('00000000219161038') }
116
187
  end
117
188
 
118
189
  context 'that only has an 8 digit serial number' do
119
190
  let(:account_number) { '6240-21916103' }
120
191
 
121
- its([:bank_code]) { is_expected.to eq('600') }
122
- its([:account_number]) { is_expected.to eq('00000000021916103') }
192
+ its([:account_number]) { is_expected.to eq('021916103') }
193
+ its([:branch_code]) { is_expected.to eq('6240') }
194
+ its([:swift_bank_code]) { is_expected.to eq('600') }
195
+ its([:swift_account_number]) { is_expected.to eq('00000000021916103') }
123
196
  end
124
197
  end
125
198
 
126
199
  context 'with a Nordea PlusGirot clearing code' do
127
200
  let(:account_number) { '9960-3401258276' }
128
201
 
129
- its([:bank_code]) { is_expected.to eq('950') }
130
- its([:account_number]) { is_expected.to eq('00099603401258276') }
202
+ its([:account_number]) { is_expected.to eq('3401258276') }
203
+ its([:branch_code]) { is_expected.to eq('9960') }
204
+ its([:swift_bank_code]) { is_expected.to eq('950') }
205
+ its([:swift_account_number]) { is_expected.to eq('00099603401258276') }
131
206
  end
132
207
  end
133
208
 
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibandit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grey Baker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
19
+ version: '3.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.1'
26
+ version: '3.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec-its
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
33
+ version: '1.2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.1'
40
+ version: '1.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.30.1
47
+ version: 0.33.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.30.1
54
+ version: 0.33.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sax-machine
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.1'
61
+ version: '1.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.1'
68
+ version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: nokogiri
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.6'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.6'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: i18n
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 0.7.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.7.0
97
97
  description: Ibandit is a Ruby library for manipulating and validating IBANs. It allows
@@ -103,10 +103,10 @@ executables: []
103
103
  extensions: []
104
104
  extra_rdoc_files: []
105
105
  files:
106
- - .gitignore
107
- - .rubocop.yml
108
- - .rubocop_todo.yml
109
- - .travis.yml
106
+ - ".gitignore"
107
+ - ".rubocop.yml"
108
+ - ".rubocop_todo.yml"
109
+ - ".travis.yml"
110
110
  - CHANGELOG.md
111
111
  - Gemfile
112
112
  - LICENSE
@@ -131,12 +131,15 @@ files:
131
131
  - ibandit.gemspec
132
132
  - lib/ibandit.rb
133
133
  - lib/ibandit/check_digit.rb
134
+ - lib/ibandit/constants.rb
134
135
  - lib/ibandit/errors.rb
135
136
  - lib/ibandit/german_details_converter.rb
136
137
  - lib/ibandit/iban.rb
137
138
  - lib/ibandit/iban_assembler.rb
138
139
  - lib/ibandit/iban_splitter.rb
139
140
  - lib/ibandit/local_details_cleaner.rb
141
+ - lib/ibandit/pseudo_iban_assembler.rb
142
+ - lib/ibandit/pseudo_iban_splitter.rb
140
143
  - lib/ibandit/swedish_details_converter.rb
141
144
  - lib/ibandit/version.rb
142
145
  - spec/fixtures/germany_integration_test_cases.json
@@ -146,6 +149,8 @@ files:
146
149
  - spec/ibandit/iban_spec.rb
147
150
  - spec/ibandit/iban_splitter_spec.rb
148
151
  - spec/ibandit/local_details_cleaner_spec.rb
152
+ - spec/ibandit/pseudo_iban_assembler_spec.rb
153
+ - spec/ibandit/pseudo_iban_splitter_spec.rb
149
154
  - spec/ibandit/swedish_details_converter_spec.rb
150
155
  - spec/spec_helper.rb
151
156
  homepage: https://github.com/gocardless/ibandit
@@ -158,17 +163,17 @@ require_paths:
158
163
  - lib
159
164
  required_ruby_version: !ruby/object:Gem::Requirement
160
165
  requirements:
161
- - - '>='
166
+ - - ">="
162
167
  - !ruby/object:Gem::Version
163
168
  version: '0'
164
169
  required_rubygems_version: !ruby/object:Gem::Requirement
165
170
  requirements:
166
- - - '>='
171
+ - - ">="
167
172
  - !ruby/object:Gem::Version
168
173
  version: '0'
169
174
  requirements: []
170
175
  rubyforge_project:
171
- rubygems_version: 2.2.2
176
+ rubygems_version: 2.4.6
172
177
  signing_key:
173
178
  specification_version: 4
174
179
  summary: Convert national banking details into IBANs, and vice-versa.