ibandit 0.6.0 → 0.6.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: c1df2cf95c45aa65c6c465e6e84acf90bdbe129c
4
- data.tar.gz: eb5ec39059d88313840d5d3f97fbe60a65d9612a
3
+ metadata.gz: b6b28e164036f1f3d80a9e52b12af42cc8452a37
4
+ data.tar.gz: 4e9aa3c2e839cbc7ba9e133c8f4151fe90f19dfb
5
5
  SHA512:
6
- metadata.gz: d8a8c4d383522ed5295cf35495d321bd5518f3e9d487033dd3a81e4eedf49d2df3f93a2f7be89d32bc93495b01cd620cf0c7fbabab70dee71c97f82fe30679ed
7
- data.tar.gz: 1b2c6c34acbdf70762aaa588a6e7660895e318c76d2cf0b78ce6ac24276b9836c77924560507b05d54231e9e022cab0b517b2a6adbcccf70d407dc4178152b20
6
+ metadata.gz: 7dd754b8daf06d399f2332c2ad55bfb57a1630708567ba3e08d96f68c33040faf46feb2ce0732e569cde3ec3e92f8c9b0137246ba79ae3978165bf7f85405340
7
+ data.tar.gz: ce8aa651ef4e7d42c92f9a5f75863cd8f0141064ca79ec4a450a0a1207f12e5e169fac46cf8cf4bc1c4d71fbf2df3ee7d0df6199506fcd122ce5c0f8913d7368
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.6.1 - July 21, 2015
2
+
3
+ - Add Norway to LocalDetailsCleaner and IBANAssembler
4
+
1
5
  ## 0.6.0 - July 20, 2015
2
6
 
3
7
  - Add support for Sweden
data/README.md CHANGED
@@ -301,6 +301,21 @@ iban = Ibandit::IBAN.new(
301
301
  )
302
302
  iban.iban # => "NL91ABNA0417164300"
303
303
 
304
+ # Norway
305
+ iban = Ibandit::IBAN.new(
306
+ country_code: 'NO',
307
+ account_number: '1117947',
308
+ bank_code: '8601'
309
+ )
310
+ iban.iban # => "NO9386011117947"
311
+
312
+ # Norway with 11 digit account number
313
+ iban = Ibandit::IBAN.new(
314
+ country_code: 'NO',
315
+ account_number: '8601.1117947',
316
+ )
317
+ iban.iban # => "NO9386011117947"
318
+
304
319
  # Portugal
305
320
  iban = Ibandit::IBAN.new(
306
321
  country_code: 'PT',
@@ -58,6 +58,9 @@ MU:
58
58
  NL:
59
59
  :local_check_digit_position: 18
60
60
  :local_check_digit_length: 1
61
+ 'NO':
62
+ :local_check_digit_position: 15
63
+ :local_check_digit_length: 1
61
64
  PT:
62
65
  :branch_code_format: \d{4}
63
66
  :account_number_format: \d{11}\d{2}
data/data/structures.yml CHANGED
@@ -633,6 +633,8 @@ NL:
633
633
  :bban_format: \d{4}\d{6}\d{1}
634
634
  :bank_code_format: \d{4}
635
635
  :account_number_format: \d{6}\d{1}
636
+ :local_check_digit_position: 15
637
+ :local_check_digit_length: 1
636
638
  PK:
637
639
  :bank_code_position: 5
638
640
  :bank_code_length: 4
@@ -134,6 +134,28 @@ module Ibandit
134
134
  result < 10 ? result.to_s : (11 - result).to_s
135
135
  end
136
136
 
137
+ # Currently unused in this gem. This method calculates the last digit
138
+ # of a Norwegian account number when given the initial digits.
139
+ def self.norwegian(string)
140
+ weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]
141
+
142
+ scaled_values = string.chars.map.with_index do |char, index|
143
+ unless char.to_i.to_s == char
144
+ raise InvalidCharacterError,
145
+ "Unexpected non-numeric character '#{char}'"
146
+ end
147
+
148
+ char.to_i * weights[index % weights.size]
149
+ end
150
+
151
+ if scaled_values[4] == 0 && scaled_values[5] == 0
152
+ scaled_values = scaled_values[6..-1]
153
+ end
154
+
155
+ result = 11 - scaled_values.inject(:+) % 11
156
+ result < 10 ? result.to_s : '0'
157
+ end
158
+
137
159
  # Currently unused in this gem. This method calculates the last digit
138
160
  # of a Finnish account number when given the initial digits (in electronic
139
161
  # format).
@@ -1,7 +1,7 @@
1
1
  module Ibandit
2
2
  module IBANAssembler
3
3
  SUPPORTED_COUNTRY_CODES = %w(AT BE CY DE EE ES FI FR GB GR IE IT LT LU LV MC
4
- MT NL PT SE SI SK SM).freeze
4
+ MT NL NO PT SE SI SK SM).freeze
5
5
 
6
6
  EXCEPTION_COUNTRY_CODES = %w(IT SM BE).freeze
7
7
 
@@ -84,7 +84,7 @@ module Ibandit
84
84
 
85
85
  def self.required_fields(country_code)
86
86
  case country_code
87
- when *%w(AT CY DE EE FI LT LU LV NL SE SI SK)
87
+ when *%w(AT CY DE EE FI LT LU LV NL NO SE SI SK)
88
88
  %i(bank_code account_number)
89
89
  when 'BE'
90
90
  %i(account_number)
@@ -1,7 +1,7 @@
1
1
  module Ibandit
2
2
  module LocalDetailsCleaner
3
3
  SUPPORTED_COUNTRY_CODES = %w(AT BE CY DE EE ES FI FR GB GR IE IT LT LU LV MC
4
- MT NL PT SE SI SK SM).freeze
4
+ MT NL NO PT SE SI SK SM).freeze
5
5
 
6
6
  def self.clean(local_details)
7
7
  country_code = local_details[:country_code]
@@ -29,7 +29,7 @@ module Ibandit
29
29
  case country_code
30
30
  when 'AT', 'CY', 'DE', 'FI', 'LT', 'LU', 'LV', 'NL', 'SI', 'SK'
31
31
  %i(bank_code account_number)
32
- when 'BE', 'EE', 'ES', 'SE'
32
+ when 'BE', 'EE', 'ES', 'SE', 'NO'
33
33
  %i(account_number)
34
34
  when 'GB', 'IE', 'MT'
35
35
  if Ibandit.bic_finder.nil? then %i(bank_code branch_code account_number)
@@ -290,6 +290,25 @@ module Ibandit
290
290
  }
291
291
  end
292
292
 
293
+ def self.clean_no_details(local_details)
294
+ # This method supports being passed the component IBAN parts, as defined
295
+ # by SWIFT, or a single 11 digit string.
296
+ if local_details[:bank_code]
297
+ bank_code = local_details[:bank_code]
298
+ account_number = local_details[:account_number]
299
+ else
300
+ cleaned_acct_number = local_details[:account_number].gsub(/[-.\s]/, '')
301
+
302
+ bank_code = cleaned_acct_number.slice(0, 4)
303
+ account_number = cleaned_acct_number[4..-1]
304
+ end
305
+
306
+ {
307
+ bank_code: bank_code,
308
+ account_number: account_number
309
+ }
310
+ end
311
+
293
312
  def self.clean_pt_details(local_details)
294
313
  local_details
295
314
  end
@@ -1,3 +1,3 @@
1
1
  module Ibandit
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.6.1'.freeze
3
3
  end
@@ -104,6 +104,28 @@ describe Ibandit::CheckDigit do
104
104
  end
105
105
  end
106
106
 
107
+ describe '.norwegian' do
108
+ subject { described_class.norwegian(account_number) }
109
+
110
+ let(:account_number) { '8601111794' }
111
+ it { is_expected.to eq('7') }
112
+
113
+ context 'with another account number (double checking!)' do
114
+ let(:account_number) { '8601549472' }
115
+ it { is_expected.to eq('9') }
116
+ end
117
+
118
+ context 'with a third account number (triple checking!)' do
119
+ let(:account_number) { '3000501790' }
120
+ it { is_expected.to eq('0') }
121
+ end
122
+
123
+ context 'with a non-numeric character' do
124
+ let(:account_number) { '1BAD2014' }
125
+ specify { expect { subject }.to raise_error(/non-numeric character/) }
126
+ end
127
+ end
128
+
107
129
  describe '.slovakian_prefix' do
108
130
  subject { described_class.slovakian_prefix(account_number) }
109
131
 
@@ -524,6 +524,32 @@ describe Ibandit::IBANAssembler do
524
524
  end
525
525
  end
526
526
 
527
+ context 'with NO as the country_code' do
528
+ let(:args) do
529
+ {
530
+ country_code: 'NO',
531
+ bank_code: '8601',
532
+ account_number: '1117947'
533
+ }
534
+ end
535
+
536
+ it { is_expected.to eq('NO9386011117947') }
537
+
538
+ it_behaves_like 'allows round trips', 'NO93 8601 1117 947'
539
+
540
+ context 'without a bank_code' do
541
+ before { args.delete(:bank_code) }
542
+ before { args[:account_number] = '86011117947' }
543
+
544
+ it { is_expected.to be_nil }
545
+ end
546
+
547
+ context 'without an account_number' do
548
+ before { args.delete(:account_number) }
549
+ it { is_expected.to be_nil }
550
+ end
551
+ end
552
+
527
553
  context 'with PT as the country_code' do
528
554
  let(:args) do
529
555
  {
@@ -658,6 +658,28 @@ describe Ibandit::LocalDetailsCleaner do
658
658
  end
659
659
  end
660
660
 
661
+ context 'Norway' do
662
+ let(:country_code) { 'NO' }
663
+ let(:bank_code) { '8601' }
664
+ let(:account_number) { '1117947' }
665
+
666
+ it { is_expected.to eq(local_details) }
667
+
668
+ context 'with bank and branch codes in the account number' do
669
+ let(:bank_code) { nil }
670
+ let(:branch_code) { nil }
671
+ let(:account_number) { '8601.1117947' }
672
+
673
+ its([:bank_code]) { is_expected.to eq('8601') }
674
+ its([:account_number]) { is_expected.to eq('1117947') }
675
+ end
676
+
677
+ context 'without an account number' do
678
+ let(:account_number) { nil }
679
+ it { is_expected.to eq(local_details) }
680
+ end
681
+ end
682
+
661
683
  context 'Portugal' do
662
684
  let(:country_code) { 'PT' }
663
685
  let(:bank_code) { '0002' }
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.6.0
4
+ version: 0.6.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-07-20 00:00:00.000000000 Z
11
+ date: 2015-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec