ibandit 0.6.6 → 0.7.0

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: f800e698be58f3378b478f197526c5d2bdec8770
4
- data.tar.gz: f8650d0eca790ea52617ea1b46da45c5c7f47f3a
3
+ metadata.gz: 53b3af5d1ef9ac7b61de43b1cc268380af1e1242
4
+ data.tar.gz: 751d53c25ff31c8a44f7cd334f76dac3389d8c0e
5
5
  SHA512:
6
- metadata.gz: 07b6d6a4a99a90ebb8810b11aed7c8de97d8ce27c5c25a12902761650c49a88a2cd947f9e1fda776917a90d57cb20f55d9f871cd2d3977baf971bb831a9e9955
7
- data.tar.gz: 0b895a47575ec3722376372b938218363d7bd996345932d4e6627242e5ca50b47680f7fd3cd425fca02769a59e42f7f08344660e8025d1b4068177e317576f35
6
+ metadata.gz: a8c6fa27a0efa6909f0783d5257bcce17ade3e21a1030078056854e8f3638e27568c61fe27485ab594f17bb9a0ce818206b521a463821e45f711fb23a50d1af8
7
+ data.tar.gz: bf770b81e770a5ed0037ae3b8ef810e84043f9355eadef160fe8cfcde8fd8321c34a8d2be3392a39dc97ebdb15fd879b4907fef7196571a5523b691ec4d1cc79
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.7.0 - August 11, 2015
2
+ - Remove all unused `CheckDigit` methods
3
+
1
4
  ## 0.6.6 - July 31, 2015
2
5
  - Add Croatia to LocalDetailsCleaner and IBANAssembler
3
6
  - Add Czech Republic to LocalDetailsCleaner and IBANAssembler
@@ -1,7 +1,7 @@
1
1
  module Ibandit
2
2
  module CheckDigit
3
- def self.mod_97_10(string)
4
- chars = string + '00'
3
+ def self.iban(country_code, bban)
4
+ chars = bban + country_code + '00'
5
5
  digits = chars.bytes.map do |byte|
6
6
  case byte
7
7
  when 48..57 then byte.chr # 0..9
@@ -15,23 +15,6 @@ module Ibandit
15
15
  format('%02d', 98 - remainder)
16
16
  end
17
17
 
18
- # Currently unused in this gem. This method calculates a mod 11
19
- # check digit from the string of digits passed in. These check
20
- # digits are used in the 1st and 2nd digits of local Spanish
21
- # account numbers.
22
- def self.spanish(string)
23
- padded_string = string.rjust(10, '0')
24
- scaled_values = padded_string.chars.map.with_index do |digit, index|
25
- unless digit.to_i.to_s == digit
26
- raise InvalidCharacterError,
27
- "Unexpected non-numeric character '#{digit}'"
28
- end
29
- Integer(digit) * (2**index % 11)
30
- end
31
- result = 11 - scaled_values.inject(:+) % 11
32
- result < 10 ? result.to_s : (11 - result).to_s
33
- end
34
-
35
18
  def self.italian(string)
36
19
  odd_mapping = {
37
20
  'A' => 1, 'B' => 0, 'C' => 5, 'D' => 7, 'E' => 9, 'F' => 13,
@@ -58,204 +41,5 @@ module Ibandit
58
41
 
59
42
  (scaled_values.inject(:+) % 26 + 65).chr
60
43
  end
61
-
62
- # Currently unused in this gem. This method calculates the last two digits
63
- # of a Belgian account number when given the first ten digits.
64
- def self.belgian(string)
65
- remainder = string.to_i % 97
66
- return format('%02d', remainder) unless remainder.zero?
67
- '97'
68
- end
69
-
70
- # Currently unused in this gem. This method calculates the last digit
71
- # of a Estonian account number when given the initial digits.
72
- def self.estonian(string)
73
- weights = [7, 3, 1]
74
-
75
- scaled_values = string.reverse.chars.map.with_index do |char, index|
76
- unless char.to_i.to_s == char
77
- raise InvalidCharacterError,
78
- "Unexpected non-numeric character '#{char}'"
79
- end
80
-
81
- char.to_i * weights[index % weights.size]
82
- end
83
-
84
- (scaled_values.inject(:+) % 10).to_s
85
- end
86
-
87
- # Currently unused in this gem. This method calculates the last digit
88
- # of a Hungarian account number when given the initial digits.
89
- def self.hungarian(string)
90
- weights = [9, 7, 3, 1]
91
-
92
- scaled_values = string.chars.map.with_index do |char, index|
93
- unless char.to_i.to_s == char
94
- raise InvalidCharacterError,
95
- "Unexpected non-numeric character '#{char}'"
96
- end
97
-
98
- char.to_i * weights[index % weights.size]
99
- end
100
-
101
- result = 10 - scaled_values.inject(:+) % 10
102
- result < 10 ? result.to_s : '0'
103
- end
104
-
105
- # Currently unused in this gem. This method calculates the last digit
106
- # of a Croatian account number when given the initial digits.
107
- def self.croatian(string)
108
- calculation = string.chars.map.reduce(10) do |total, char|
109
- unless char.to_i.to_s == char
110
- raise InvalidCharacterError,
111
- "Unexpected non-numeric character '#{char}'"
112
- end
113
-
114
- calc = (char.to_i + total) % 10
115
- calc = calc == 0 ? 10 : calc
116
- (calc * 2) % 11
117
- end
118
-
119
- ((11 - calculation) % 10).to_s
120
- end
121
-
122
- # Currently unused in this gem. This method calculates the penultimate digit
123
- # of an Icelandic kennitala (included in the account number) when given the
124
- # first 8 digits.
125
- def self.icelandic(string)
126
- weights = [3, 2, 7, 6, 5, 4, 3, 2]
127
-
128
- scaled_values = string.chars.map.with_index do |char, index|
129
- unless char.to_i.to_s == char
130
- raise InvalidCharacterError,
131
- "Unexpected non-numeric character '#{char}'"
132
- end
133
-
134
- char.to_i * weights[index % weights.size]
135
- end
136
-
137
- result = 11 - scaled_values.inject(:+) % 11
138
- result < 10 ? result.to_s : '0'
139
- end
140
-
141
- # Currently unused in this gem. This method calculates the last digit
142
- # of a Slovakian account number (basic) when given the initial digits.
143
- def self.slovakian_prefix(string)
144
- weights = [10, 5, 8, 4, 2]
145
-
146
- scaled_values = string.chars.map.with_index do |char, index|
147
- unless char.to_i.to_s == char
148
- raise InvalidCharacterError,
149
- "Unexpected non-numeric character '#{char}'"
150
- end
151
-
152
- char.to_i * weights[index]
153
- end
154
-
155
- (11 - scaled_values.inject(:+) % 11).to_s
156
- end
157
-
158
- # Currently unused in this gem. This method calculates the last digit
159
- # of a Slovakian account number prefix when given the initial digits.
160
- def self.slovakian_basic(string)
161
- weights = [6, 3, 7, 9, 10, 5, 8, 4, 2]
162
-
163
- scaled_values = string.chars.map.with_index do |char, index|
164
- unless char.to_i.to_s == char
165
- raise InvalidCharacterError,
166
- "Unexpected non-numeric character '#{char}'"
167
- end
168
-
169
- char.to_i * weights[index]
170
- end
171
-
172
- (11 - scaled_values.inject(:+) % 11).to_s
173
- end
174
-
175
- # Currently unused in this gem. This method calculates the last digit
176
- # of a Dutch account number when given the first nine digits.
177
- def self.dutch(string)
178
- scaled_values = string.reverse.chars.map.with_index do |char, index|
179
- unless char.to_i.to_s == char
180
- raise InvalidCharacterError,
181
- "Unexpected non-numeric character '#{char}'"
182
- end
183
-
184
- char.to_i * (index + 2)
185
- end
186
-
187
- result = 11 - scaled_values.inject(:+) % 11
188
- result < 10 ? result.to_s : (11 - result).to_s
189
- end
190
-
191
- # Currently unused in this gem. This method calculates the last digit
192
- # of a Norwegian account number when given the initial digits.
193
- def self.norwegian(string)
194
- weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]
195
-
196
- scaled_values = string.chars.map.with_index do |char, index|
197
- unless char.to_i.to_s == char
198
- raise InvalidCharacterError,
199
- "Unexpected non-numeric character '#{char}'"
200
- end
201
-
202
- char.to_i * weights[index % weights.size]
203
- end
204
-
205
- if scaled_values[4] == 0 && scaled_values[5] == 0
206
- scaled_values = scaled_values[6..-1]
207
- end
208
-
209
- result = 11 - scaled_values.inject(:+) % 11
210
- result < 10 ? result.to_s : '0'
211
- end
212
-
213
- # Currently unused in this gem. This method calculates the last digit
214
- # of a Finnish account number when given the initial digits (in electronic
215
- # format).
216
- def self.lund(string)
217
- weights = [2, 1]
218
-
219
- scaled_values = string.reverse.chars.map.with_index do |char, index|
220
- unless char.to_i.to_s == char
221
- raise InvalidCharacterError,
222
- "Unexpected non-numeric character '#{char}'"
223
- end
224
-
225
- scaled_value = char.to_i * weights[index % weights.size]
226
- scaled_value < 10 ? scaled_value : scaled_value % 10 + 1
227
- end
228
-
229
- (10 - scaled_values.inject(:+) % 10).to_s
230
- end
231
-
232
- def self.rib(bank_code, branch_code, account_number)
233
- remainder = 97 - (89 * rib_value(bank_code) +
234
- 15 * rib_value(branch_code) +
235
- 3 * rib_value(account_number)) % 97
236
- format('%02d', remainder)
237
- end
238
-
239
- def self.iban(country_code, bban)
240
- mod_97_10(bban + country_code)
241
- end
242
-
243
- def self.rib_value(string)
244
- rib_mapping = {
245
- 'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7,
246
- 'H' => 8, 'I' => 9, 'J' => 1, 'K' => 2, 'L' => 3, 'M' => 4, 'N' => 5,
247
- 'O' => 6, 'P' => 7, 'Q' => 8, 'R' => 9, 'S' => 2, 'T' => 3, 'U' => 4,
248
- 'V' => 5, 'W' => 6, 'X' => 7, 'Y' => 8, 'Z' => 9, '0' => 0, '1' => 1,
249
- '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8,
250
- '9' => 9
251
- }
252
-
253
- string.chars.map do |character|
254
- unless rib_mapping[character]
255
- raise InvalidCharacterError, "Unexpected byte '#{character}' in RIB"
256
- end
257
- rib_mapping[character]
258
- end.join.to_i
259
- end
260
44
  end
261
45
  end
@@ -1,3 +1,3 @@
1
1
  module Ibandit
2
- VERSION = '0.6.6'.freeze
2
+ VERSION = '0.7.0'.freeze
3
3
  end
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.6
4
+ version: 0.7.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-07-31 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -141,7 +141,6 @@ files:
141
141
  - lib/ibandit/version.rb
142
142
  - spec/fixtures/germany_integration_test_cases.json
143
143
  - spec/fixtures/germany_unit_test_cases.json
144
- - spec/ibandit/check_digit_spec.rb
145
144
  - spec/ibandit/german_details_converter_spec.rb
146
145
  - spec/ibandit/iban_assembler_spec.rb
147
146
  - spec/ibandit/iban_spec.rb
@@ -1,238 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ibandit::CheckDigit do
4
- describe '.mod_97_10' do
5
- subject { described_class.mod_97_10(account_number) }
6
-
7
- context 'with a non-numeric character' do
8
- let(:account_number) { 'hhhh' }
9
- specify { expect { subject }.to raise_error(/non-alphanumeric/) }
10
- end
11
- end
12
-
13
- describe '.spanish' do
14
- subject { described_class.spanish(account_number) }
15
-
16
- context 'sequence that should give a check digit of 0' do
17
- let(:account_number) { '12345678' }
18
- it { is_expected.to eq('0') }
19
- end
20
-
21
- context 'sequence that should give a check digit of 8' do
22
- let(:account_number) { '0000012345' }
23
- it { is_expected.to eq('8') }
24
- end
25
-
26
- context 'with a non-numeric character' do
27
- let(:account_number) { '000001234A' }
28
- it 'raises an error' do
29
- expect { subject }.to raise_error(Ibandit::InvalidCharacterError)
30
- end
31
- end
32
-
33
- context 'with a string that is fewer than 10 characters' do
34
- let(:account_number) { '20386010' }
35
-
36
- it 'zero-pads the string to get the correct check digit' do
37
- expect(subject).to eq('5')
38
- end
39
- end
40
- end
41
-
42
- describe '.belgian' do
43
- subject { described_class.belgian(account_number) }
44
-
45
- let(:account_number) { '5100075470' }
46
- it { is_expected.to eq('61') }
47
-
48
- context 'with an account number which is a factor of 97' do
49
- let(:account_number) { '1030343409' }
50
- it { is_expected.to eq('97') }
51
- end
52
- end
53
-
54
- describe '.lund' do
55
- subject { described_class.lund(account_number) }
56
-
57
- let(:account_number) { '1200300002088' }
58
- it { is_expected.to eq('3') }
59
-
60
- context 'with another account number (double checking!)' do
61
- let(:account_number) { '1428350017114' }
62
- it { is_expected.to eq('1') }
63
- end
64
-
65
- context 'with a non-numeric character' do
66
- let(:account_number) { '1BAD2014' }
67
- specify { expect { subject }.to raise_error(/non-numeric character/) }
68
- end
69
- end
70
-
71
- describe '.estonian' do
72
- subject { described_class.estonian(account_number) }
73
-
74
- context "with an account_number that doesn't start with a zero" do
75
- let(:account_number) { '22102014568' }
76
- it { is_expected.to eq('5') }
77
- end
78
-
79
- context 'with leading zeros' do
80
- let(:account_number) { '0022102014568' }
81
- it { is_expected.to eq('5') }
82
- end
83
-
84
- context 'with a non-numeric character' do
85
- let(:account_number) { '1BAD2014' }
86
- specify { expect { subject }.to raise_error(/non-numeric character/) }
87
- end
88
- end
89
-
90
- describe '.dutch' do
91
- subject { described_class.dutch(account_number) }
92
-
93
- let(:account_number) { '041716430' }
94
- it { is_expected.to eq('0') }
95
-
96
- context 'with another account number (double checking!)' do
97
- let(:account_number) { '030006526' }
98
- it { is_expected.to eq('4') }
99
- end
100
-
101
- context 'with a non-numeric character' do
102
- let(:account_number) { '1BAD2014' }
103
- specify { expect { subject }.to raise_error(/non-numeric character/) }
104
- end
105
- end
106
-
107
- describe '.hungarian' do
108
- subject { described_class.hungarian(account_number) }
109
-
110
- let(:account_number) { '1234567' }
111
- it { is_expected.to eq('6') }
112
-
113
- context 'with another account number (double checking!)' do
114
- let(:account_number) { '1111101' }
115
- it { is_expected.to eq('8') }
116
- end
117
-
118
- context 'with all zeros' do
119
- let(:account_number) { '0000000' }
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
-
129
- describe '.croatian' do
130
- subject { described_class.croatian(account_number) }
131
-
132
- let(:account_number) { '0823' }
133
- it { is_expected.to eq('5') }
134
-
135
- context 'with another account number (double checking!)' do
136
- let(:account_number) { '100100' }
137
- it { is_expected.to eq('5') }
138
- end
139
-
140
- context 'with all zeros' do
141
- let(:account_number) { '186300016' }
142
- it { is_expected.to eq('0') }
143
- end
144
-
145
- context 'with a non-numeric character' do
146
- let(:account_number) { '1BAD2014' }
147
- specify { expect { subject }.to raise_error(/non-numeric character/) }
148
- end
149
- end
150
-
151
- describe '.icelandic' do
152
- subject { described_class.icelandic(kennitala) }
153
-
154
- let(:kennitala) { '52121206' }
155
- it { is_expected.to eq('3') }
156
-
157
- context 'with another kennitala (double checking!)' do
158
- let(:kennitala) { '42027802' }
159
- it { is_expected.to eq('0') }
160
- end
161
-
162
- context 'with a third kennitala (triple checking!)' do
163
- let(:kennitala) { '12017433' }
164
- it { is_expected.to eq('9') }
165
- end
166
-
167
- context 'with a non-numeric character' do
168
- let(:kennitala) { '1BAD2014' }
169
- specify { expect { subject }.to raise_error(/non-numeric character/) }
170
- end
171
- end
172
-
173
- describe '.norwegian' do
174
- subject { described_class.norwegian(account_number) }
175
-
176
- let(:account_number) { '8601111794' }
177
- it { is_expected.to eq('7') }
178
-
179
- context 'with another account number (double checking!)' do
180
- let(:account_number) { '8601549472' }
181
- it { is_expected.to eq('9') }
182
- end
183
-
184
- context 'with a third account number (triple checking!)' do
185
- let(:account_number) { '3000501790' }
186
- it { is_expected.to eq('0') }
187
- end
188
-
189
- context 'with a non-numeric character' do
190
- let(:account_number) { '1BAD2014' }
191
- specify { expect { subject }.to raise_error(/non-numeric character/) }
192
- end
193
- end
194
-
195
- describe '.slovakian_prefix' do
196
- subject { described_class.slovakian_prefix(account_number) }
197
-
198
- let(:account_number) { '00001' }
199
- it { is_expected.to eq('9') }
200
-
201
- context 'with a non-numeric character' do
202
- let(:account_number) { '1BAD2014' }
203
- specify { expect { subject }.to raise_error(/non-numeric character/) }
204
- end
205
- end
206
-
207
- describe '.slovakian_basic' do
208
- subject { described_class.slovakian_basic(account_number) }
209
-
210
- let(:account_number) { '874263754' }
211
- it { is_expected.to eq('1') }
212
-
213
- context 'with a non-numeric character' do
214
- let(:account_number) { '1BAD2014' }
215
- specify { expect { subject }.to raise_error(/non-numeric character/) }
216
- end
217
- end
218
-
219
- describe '.rib' do
220
- subject { described_class.rib(bank_code, branch_code, account_number) }
221
-
222
- context 'with some non-numeric characters' do
223
- let(:bank_code) { '12BD4' }
224
- let(:branch_code) { '367WX' }
225
- let(:account_number) { '12345678912' }
226
-
227
- it { is_expected.to eq('20') }
228
- end
229
-
230
- context 'with numeric characters' do
231
- let(:bank_code) { '12244' }
232
- let(:branch_code) { '36767' }
233
- let(:account_number) { '12345678912' }
234
-
235
- it { is_expected.to eq('20') }
236
- end
237
- end
238
- end