ibandit 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efe0d22849b9038cd0f8ba2d2a5ca9b73af14137
4
- data.tar.gz: dbf58fdc4ba8242d3676b76b01f194a5d58c4412
3
+ metadata.gz: 79bb8d78b071a6a3cfb74852b2f62641af34014d
4
+ data.tar.gz: 3868681d7108888d0259ff51f145bfefb481035f
5
5
  SHA512:
6
- metadata.gz: 254642c61af11750bc56d04714521b778a34ac4f9852d65eb426ab50cd820c828a90efd180058e2c6b453a4745162ecc731aaf9e4cbcd2fccbe156017d042edb
7
- data.tar.gz: 1edbf221f87f7097760555697d26ec15bc7896906b3f63fd385c845f897cefebf17fa9dd74da3dff8e422e61004f3d132739f4a5e924c5cd4d14d5035c34e9f5
6
+ metadata.gz: b3e0bb71e33693b7b7ad0a67a3b7aa911dd3d1ef0c0f2e1c1cfa4ca2a0815f2b4f3701cf76f6414fb674da299dc6c06cef64ad2edc98dfad990c5a9095dcff2e
7
+ data.tar.gz: 859b58bd96989e6bf05ab2127fb29939ad4db924bf816d97c5bfd86ee6b13d424d51ee7f6a3536def34375b17fab2bd9489f7dc1178ed4f98f06b921a294b3ad
@@ -1,3 +1,7 @@
1
+ ## 0.3.1 - February 14, 2015
2
+
3
+ - Add Malta to LocalDetailsCleaner and IBANAssembler
4
+
1
5
  ## 0.3.0 - February 6, 2015
2
6
 
3
7
  - Move IBANBuilder interface into main IBAN class by overloading its constructor
@@ -13,7 +17,6 @@
13
17
 
14
18
  - Add GermanDetailsConverter
15
19
 
16
-
17
20
  ## 0.1.1 - January 8, 2015
18
21
 
19
22
  - Add zero-padding to CheckDigit.spanish
data/README.md CHANGED
@@ -138,7 +138,7 @@ To build an IBAN from local details:
138
138
 
139
139
  ```ruby
140
140
  # Austria
141
- iban = Ibandit::IBANBuilder.build(
141
+ iban = Ibandit::IBAN.new(
142
142
  country_code: 'AT',
143
143
  account_number: '234573201',
144
144
  bank_code: '19043'
@@ -146,14 +146,14 @@ iban = Ibandit::IBANBuilder.build(
146
146
  iban.iban # => "AT611904300234573201"
147
147
 
148
148
  # Belgium
149
- iban = Ibandit::IBANBuilder.build(
149
+ iban = Ibandit::IBAN.new(
150
150
  country_code: 'BE',
151
151
  account_number: '510-0075470-61'
152
152
  )
153
153
  iban.iban # => "BE62510007547061"
154
154
 
155
155
  # Cyprus
156
- iban = Ibandit::IBANBuilder.build(
156
+ iban = Ibandit::IBAN.new(
157
157
  country_code: 'CY',
158
158
  account_number: '1200527600',
159
159
  bank_code: '002',
@@ -162,7 +162,7 @@ iban = Ibandit::IBANBuilder.build(
162
162
  iban.iban # => "CY17002001280000001200527600"
163
163
 
164
164
  # Germany
165
- iban = Ibandit::IBANBuilder.build(
165
+ iban = Ibandit::IBAN.new(
166
166
  country_code: 'DE',
167
167
  bank_code: '37040044',
168
168
  account_number: '0532013000'
@@ -170,14 +170,14 @@ iban = Ibandit::IBANBuilder.build(
170
170
  iban.iban # => "DE89370400440532013000"
171
171
 
172
172
  # Estonia
173
- iban = Ibandit::IBANBuilder.build(
173
+ iban = Ibandit::IBAN.new(
174
174
  country_code: 'EE',
175
175
  account_number: '111020145685'
176
176
  )
177
177
  iban.iban # => "EE412200111020145685"
178
178
 
179
179
  # Finland
180
- iban = Ibandit::IBANBuilder.build(
180
+ iban = Ibandit::IBAN.new(
181
181
  country_code: 'FI',
182
182
  bank_code: '123456'
183
183
  account_number: '785'
@@ -185,7 +185,7 @@ iban = Ibandit::IBANBuilder.build(
185
185
  iban.iban # => "FI2112345600000785"
186
186
 
187
187
  # France
188
- iban = Ibandit::IBANBuilder.build(
188
+ iban = Ibandit::IBAN.new(
189
189
  country_code: 'FR',
190
190
  bank_code: '20041',
191
191
  branch_code: '01005',
@@ -194,7 +194,7 @@ iban = Ibandit::IBANBuilder.build(
194
194
  iban.iban # => "FR1420041010050500013M02606"
195
195
 
196
196
  # United Kingdom
197
- iban = Ibandit::IBANBuilder.build(
197
+ iban = Ibandit::IBAN.new(
198
198
  country_code: 'GB',
199
199
  bank_code: 'BARC', # optional if a BIC finder is configured
200
200
  branch_code: '200000',
@@ -203,7 +203,7 @@ iban = Ibandit::IBANBuilder.build(
203
203
  iban.iban # => "GB60BARC20000055779911"
204
204
 
205
205
  # Ireland
206
- iban = Ibandit::IBANBuilder.build(
206
+ iban = Ibandit::IBAN.new(
207
207
  country_code: 'IE',
208
208
  bank_code: 'AIBK', # optional if a BIC finder is configured
209
209
  branch_code: '931152',
@@ -212,7 +212,7 @@ iban = Ibandit::IBANBuilder.build(
212
212
  iban.iban # => "IE29AIBK93115212345678"
213
213
 
214
214
  # Italy
215
- iban = Ibandit::IBANBuilder.build(
215
+ iban = Ibandit::IBAN.new(
216
216
  country_code: 'IT',
217
217
  bank_code: '05428',
218
218
  branch_code: '11101',
@@ -221,7 +221,7 @@ iban = Ibandit::IBANBuilder.build(
221
221
  iban.iban # => "IT60X0542811101000000123456"
222
222
 
223
223
  # Latvia
224
- iban = Ibandit::IBANBuilder.build(
224
+ iban = Ibandit::IBAN.new(
225
225
  country_code: 'LV',
226
226
  account_number: '1234567890123',
227
227
  bank_code: 'BANK'
@@ -229,7 +229,7 @@ iban = Ibandit::IBANBuilder.build(
229
229
  iban.iban # => "LV72BANK1234567890123"
230
230
 
231
231
  # Lithuania
232
- iban = Ibandit::IBANBuilder.build(
232
+ iban = Ibandit::IBAN.new(
233
233
  country_code: 'LT',
234
234
  account_number: '11101001000',
235
235
  bank_code: '10000'
@@ -237,7 +237,7 @@ iban = Ibandit::IBANBuilder.build(
237
237
  iban.iban # => "LT1000011101001000"
238
238
 
239
239
  # Luxembourg
240
- iban = Ibandit::IBANBuilder.build(
240
+ iban = Ibandit::IBAN.new(
241
241
  country_code: 'LU',
242
242
  account_number: '1234567890123',
243
243
  bank_code: 'BANK'
@@ -245,7 +245,7 @@ iban = Ibandit::IBANBuilder.build(
245
245
  iban.iban # => "LU75BANK1234567890123"
246
246
 
247
247
  # Monaco
248
- iban = Ibandit::IBANBuilder.build(
248
+ iban = Ibandit::IBAN.new(
249
249
  country_code: 'MC',
250
250
  bank_code: '20041',
251
251
  branch_code: '01005',
@@ -253,8 +253,17 @@ iban = Ibandit::IBANBuilder.build(
253
253
  )
254
254
  iban.iban # => "MC9320041010050500013M02606"
255
255
 
256
+ # Malta
257
+ iban = Ibandit::IBAN.new(
258
+ country_code: 'MT',
259
+ bank_code: 'MMEB', # optional if a BIC finder is configured
260
+ branch_code: '44093',
261
+ account_number: '9027293051'
262
+ )
263
+ iban.iban # => "MT98MMEB44093000000009027293051"
264
+
256
265
  # The Netherlands
257
- iban = Ibandit::IBANBuilder.build(
266
+ iban = Ibandit::IBAN.new(
258
267
  country_code: 'NL',
259
268
  account_number: '0417164300',
260
269
  bank_code: 'ABNA'
@@ -262,7 +271,7 @@ iban = Ibandit::IBANBuilder.build(
262
271
  iban.iban # => "NL91ABNA0417164300"
263
272
 
264
273
  # Portugal
265
- iban = Ibandit::IBANBuilder.build(
274
+ iban = Ibandit::IBAN.new(
266
275
  country_code: 'PT',
267
276
  bank_code: '0002',
268
277
  branch_code: '0023',
@@ -271,7 +280,7 @@ iban = Ibandit::IBANBuilder.build(
271
280
  iban.iban # => "PT50000200230023843000578"
272
281
 
273
282
  # Slovakia
274
- iban = Ibandit::IBANBuilder.build(
283
+ iban = Ibandit::IBAN.new(
275
284
  country_code: 'SK',
276
285
  bank_code: '1200',
277
286
  account_number_prefix: '19',
@@ -280,7 +289,7 @@ iban = Ibandit::IBANBuilder.build(
280
289
  iban.iban # => "SK3112000000198742637541"
281
290
 
282
291
  # Slovenia
283
- iban = Ibandit::IBANBuilder.build(
292
+ iban = Ibandit::IBAN.new(
284
293
  country_code: 'SI',
285
294
  bank_code: '19100',
286
295
  account_number: '1234'
@@ -288,7 +297,7 @@ iban = Ibandit::IBANBuilder.build(
288
297
  iban.iban # => "SI56191000000123438"
289
298
 
290
299
  # Spain
291
- iban = Ibandit::IBANBuilder.build(
300
+ iban = Ibandit::IBAN.new(
292
301
  country_code: 'ES',
293
302
  bank_code: '2310',
294
303
  branch_code: '0001',
@@ -297,14 +306,14 @@ iban = Ibandit::IBANBuilder.build(
297
306
  iban.iban # => "ES8023100001180000012345"
298
307
 
299
308
  # Spain with 20 digit account number
300
- iban = Ibandit::IBANBuilder.build(
309
+ iban = Ibandit::IBAN.new(
301
310
  country_code: 'ES',
302
311
  account_number: '23100001180000012345'
303
312
  )
304
313
  iban.iban # => "ES8023100001180000012345"
305
314
 
306
315
  # San Marino
307
- iban = Ibandit::IBANBuilder.build(
316
+ iban = Ibandit::IBAN.new(
308
317
  country_code: 'SM',
309
318
  bank_code: '05428',
310
319
  branch_code: '11101',
data/TODO.md CHANGED
@@ -1,7 +1,4 @@
1
1
  - Build IBANs from national banking details for each SEPA country
2
2
  - GREECE: TODO
3
- - MALTA: TODO (maybe - not sure if local details are still used in Malta).
4
-
5
- - Clarify Lithuanian check digits
6
3
 
7
4
  - Specs for IBANSTRUCTURE parser
@@ -1,7 +1,7 @@
1
1
  module Ibandit
2
2
  module IBANAssembler
3
- SUPPORTED_COUNTRY_CODES = %w(AT BE CY DE EE ES FI FR GB IE IT LT LU LV MC NL
4
- PT SI SK SM).freeze
3
+ SUPPORTED_COUNTRY_CODES = %w(AT BE CY DE EE ES FI FR GB IE IT LT LU LV MC MT
4
+ NL PT SI SK SM).freeze
5
5
 
6
6
  EXCEPTION_COUNTRY_CODES = %w(IT SM BE).freeze
7
7
 
@@ -1,7 +1,7 @@
1
1
  module Ibandit
2
2
  module LocalDetailsCleaner
3
- SUPPORTED_COUNTRY_CODES = %w(AT BE CY DE EE ES FI FR GB IE IT LT LU LV MC NL
4
- PT SI SK SM).freeze
3
+ SUPPORTED_COUNTRY_CODES = %w(AT BE CY DE EE ES FI FR GB IE IT LT LU LV MC MT
4
+ NL PT SI SK SM).freeze
5
5
 
6
6
  def self.clean(local_details)
7
7
  country_code = local_details[:country_code]
@@ -31,7 +31,7 @@ module Ibandit
31
31
  %i(bank_code account_number)
32
32
  when 'BE', 'EE', 'ES'
33
33
  %i(account_number)
34
- when 'GB', 'IE'
34
+ when 'GB', 'IE', 'MT'
35
35
  if Ibandit.bic_finder.nil? then %i(bank_code branch_code account_number)
36
36
  else %i(branch_code account_number)
37
37
  end
@@ -200,21 +200,6 @@ module Ibandit
200
200
  }
201
201
  end
202
202
 
203
- def self.clean_lt_details(local_details)
204
- # Lithuanian national bank details were replaced with IBANs in 2004.
205
- local_details
206
- end
207
-
208
- def self.clean_lu_details(local_details)
209
- # Luxembourgian national bank details were replaced with IBANs in 2002.
210
- local_details
211
- end
212
-
213
- def self.clean_lv_details(local_details)
214
- # Latvian national bank details were replaced with IBANs in 2004.
215
- local_details
216
- end
217
-
218
203
  def self.clean_ie_details(local_details)
219
204
  # Ireland uses the same local details as the United Kingdom
220
205
  branch_code = local_details[:branch_code].gsub(/[-\s]/, '')
@@ -245,11 +230,47 @@ module Ibandit
245
230
  }
246
231
  end
247
232
 
233
+ def self.clean_lt_details(local_details)
234
+ # Lithuanian national bank details were replaced with IBANs in 2004.
235
+ local_details
236
+ end
237
+
238
+ def self.clean_lu_details(local_details)
239
+ # Luxembourgian national bank details were replaced with IBANs in 2002.
240
+ local_details
241
+ end
242
+
243
+ def self.clean_lv_details(local_details)
244
+ # Latvian national bank details were replaced with IBANs in 2004.
245
+ local_details
246
+ end
247
+
248
248
  def self.clean_mc_details(local_details)
249
249
  # Monaco uses the same local details method as France
250
250
  clean_fr_details(local_details)
251
251
  end
252
252
 
253
+ def self.clean_mt_details(local_details)
254
+ # Add leading zeros to account number if < 18 digits.
255
+ branch_code = local_details[:branch_code]
256
+
257
+ if local_details[:bank_code]
258
+ bank_code = local_details[:bank_code]
259
+ else
260
+ bic = Ibandit.find_bic('MT', branch_code)
261
+ bank_code = bic.nil? ? nil : bic.slice(0, 4)
262
+ end
263
+
264
+ account_number = local_details[:account_number].gsub(/[-\s]/, '')
265
+ account_number = account_number.rjust(18, '0')
266
+
267
+ {
268
+ bank_code: bank_code,
269
+ branch_code: branch_code,
270
+ account_number: account_number
271
+ }
272
+ end
273
+
253
274
  def self.clean_nl_details(local_details)
254
275
  # Add leading zeros to account number if < 10 digits.
255
276
  {
@@ -1,3 +1,3 @@
1
1
  module Ibandit
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
@@ -432,6 +432,44 @@ describe Ibandit::IBANAssembler do
432
432
  end
433
433
  end
434
434
 
435
+ context 'with MT as the country_code' do
436
+ let(:args) do
437
+ {
438
+ country_code: 'MT',
439
+ bank_code: 'MMEB',
440
+ branch_code: '44093',
441
+ account_number: '000000009027293051'
442
+ }
443
+ end
444
+
445
+ it { is_expected.to eq('MT98MMEB44093000000009027293051') }
446
+
447
+ it_behaves_like(
448
+ 'allows round trips',
449
+ 'MT98 MMEB 4409 3000 0000 0902 7293 051'
450
+ )
451
+
452
+ context 'without a branch_code' do
453
+ before { args.delete(:branch_code) }
454
+ it { is_expected.to be_nil }
455
+ end
456
+
457
+ context 'without an account_number' do
458
+ before { args.delete(:account_number) }
459
+ it { is_expected.to be_nil }
460
+ end
461
+
462
+ context 'without a bank_code' do
463
+ before { args.delete(:bank_code) }
464
+ it { is_expected.to be_nil }
465
+ end
466
+
467
+ context 'with a non-numeric branch code' do
468
+ before { args[:branch_code] = 'abc123' }
469
+ it { is_expected.to be_nil }
470
+ end
471
+ end
472
+
435
473
  context 'with NL as the country_code' do
436
474
  let(:args) do
437
475
  {
@@ -546,6 +546,60 @@ describe Ibandit::LocalDetailsCleaner do
546
546
  end
547
547
  end
548
548
 
549
+ context 'Malta' do
550
+ let(:country_code) { 'MT' }
551
+ let(:bank_code) { 'MMEB' }
552
+ let(:branch_code) { '44093' }
553
+ let(:account_number) { '000000009027293051' }
554
+
555
+ it { is_expected.to eq(local_details) }
556
+
557
+ context 'with the account number spaced' do
558
+ let(:account_number) { '9027 2930 51' }
559
+ its([:account_number]) { is_expected.to eq('000000009027293051') }
560
+ end
561
+
562
+ context 'with the account number hyphenated' do
563
+ let(:account_number) { '9027-2930-51' }
564
+ its([:account_number]) { is_expected.to eq('000000009027293051') }
565
+ end
566
+
567
+ context 'without a branch code' do
568
+ let(:branch_code) { nil }
569
+ it { is_expected.to eq(local_details) }
570
+ end
571
+
572
+ context 'without a bank code' do
573
+ let(:bank_code) { nil }
574
+ it { is_expected.to eq(local_details) }
575
+
576
+ context 'with a BIC finder set' do
577
+ let(:bic_finder) { double }
578
+ before do
579
+ allow(bic_finder).to receive(:call).with('MT', '44093').
580
+ and_return('MMEBMTMTXXX')
581
+ Ibandit.bic_finder = bic_finder
582
+ end
583
+ after { Ibandit.bic_finder = nil }
584
+
585
+ its([:bank_code]) { is_expected.to eq('MMEB') }
586
+ end
587
+ end
588
+
589
+ context 'with a bank code and BIC finder set' do
590
+ let(:bank_code) { 'OVERRIDE' }
591
+ let(:bic_finder) { double }
592
+ before do
593
+ allow(bic_finder).to receive(:call).with('MT', '44093').
594
+ and_return('MMEBMTMTXXX')
595
+ Ibandit.bic_finder = bic_finder
596
+ end
597
+ after { Ibandit.bic_finder = nil }
598
+
599
+ its([:bank_code]) { is_expected.to eq('OVERRIDE') }
600
+ end
601
+ end
602
+
549
603
  context 'Netherlands' do
550
604
  let(:country_code) { 'NL' }
551
605
  let(:bank_code) { 'ABNA' }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibandit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
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-02-06 00:00:00.000000000 Z
11
+ date: 2015-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec