banktools-se 3.3.2 → 3.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccccc22d21f8267923982fc38deeb6a399e005f7447ce10c7cad333786cae07d
4
- data.tar.gz: 9fb1a7b6cd47306bc55b206d73bd9e64a95f299d5123f957eff1894411820a58
3
+ metadata.gz: f88306b60a358141bee6be5459b368874cbacf93b902c49fa00bcb9301b5afd9
4
+ data.tar.gz: ef5e4b8daac88c910d062837481e78367eb59e58f26d3bcf90e86786c862e5bb
5
5
  SHA512:
6
- metadata.gz: b33615c06ae45f94fc8a73cf1f0b5dffcf2558bb33aaeacf9537c33f52b9f13d6d86a538e77437d866aab720040df8bf5253080915eeabb54ee56b49fe05c2f0
7
- data.tar.gz: ac5d291cc1008477b7580f372015e7a9bd1c9613f8887a21fced5ba2ac2a419396f698421f9c659f7aaf181013deb2c39cb670daa8fb3a832d32a2f455597cb5
6
+ metadata.gz: 3daa817d195a97aca47e6e96d4f1455c24f7673c8807f4299909297b3ce66718927fd4c8d2fe9b95aedd0402a74f6a014bc8e79553404f9b15d43616089b1a0b
7
+ data.tar.gz: 19e3092e3b94606ca94d8213c92bddca3e9a720cc50e90bbdc6104973593dd1ead85d19eb0be09c116b68005130bf975a5af95c549493fdb4fe0dd084a218693
@@ -6,6 +6,9 @@ on:
6
6
  pull_request:
7
7
  branches: [ master ]
8
8
 
9
+ permissions:
10
+ contents: read
11
+
9
12
  jobs:
10
13
  ruby-versions:
11
14
  uses: ruby/actions/.github/workflows/ruby_versions.yml@master
@@ -22,7 +25,7 @@ jobs:
22
25
  ruby-version: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
23
26
 
24
27
  steps:
25
- - uses: actions/checkout@v6
28
+ - uses: actions/checkout@v7
26
29
  - name: Set up Ruby ${{ matrix.ruby-version }}
27
30
  uses: ruby/setup-ruby@v1
28
31
  with:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.4.0
4
+
5
+ - Zerofill Handelsbanken serial numbers to 9 digits in `Account#serial_number` and `Account#normalize`. 8-digit serial numbers are still valid; 7 or fewer are still too short.
6
+ - A Swedbank/Sparbanken account with no serial number digits at all (e.g. "8000-2") is now too short, rather than zerofilled to all zeroes.
7
+
3
8
  ## 3.3.2
4
9
 
5
10
  - Revert erroneous changes introduced in 3.3.1
@@ -18,10 +18,11 @@ module BankTools
18
18
  3782..3782 => { name: "Nordea", serial_number_length: 10, luhn_for_serial: true }, # Personkonto.
19
19
  3783..4999 => { name: "Nordea" },
20
20
  5000..5999 => { name: "SEB" },
21
- 6000..6999 => { name: "Handelsbanken", serial_number_length: 8..9 },
21
+ # Can be 8 or 9 chars but must be zero-filled to 9.
22
+ 6000..6999 => { name: "Handelsbanken", serial_number_length: 8..9, zerofill: true },
22
23
  7000..7999 => { name: "Swedbank" },
23
- # Can be fewer chars but must be zero-filled, so let's call it 10.
24
- 8000..8999 => { name: "Swedbank", serial_number_length: 10, checksum_for_clearing: true, zerofill: true },
24
+ # Can be fewer chars but must be zero-filled to 10.
25
+ 8000..8999 => { name: "Swedbank", serial_number_length: 1..10, checksum_for_clearing: true, zerofill: true },
25
26
  9020..9029 => { name: "Länsförsäkringar Bank" },
26
27
  9040..9049 => { name: "Citibank" },
27
28
  9060..9069 => { name: "Länsförsäkringar Bank" },
@@ -38,13 +39,13 @@ module BankTools
38
39
  9260..9269 => { name: "Den Norske Bank" },
39
40
  9270..9279 => { name: "ICA Banken" },
40
41
  9280..9289 => { name: "Resurs Bank" },
41
- 9300..9349 => { name: "Sparbanken Öresund", serial_number_length: 10, zerofill: true },
42
+ 9300..9349 => { name: "Sparbanken Öresund", serial_number_length: 1..10, zerofill: true },
42
43
  9400..9449 => { name: "Forex Bank" },
43
44
  9460..9469 => { name: "GE Money Bank" },
44
45
  9470..9479 => { name: "Fortis Bank" },
45
46
  9500..9549 => { name: "Nordea/Plusgirot", serial_number_length: 1..10 },
46
47
  9550..9569 => { name: "Avanza Bank" },
47
- 9570..9579 => { name: "Sparbanken Syd", serial_number_length: 10, zerofill: true },
48
+ 9570..9579 => { name: "Sparbanken Syd", serial_number_length: 1..10, zerofill: true },
48
49
  9630..9639 => { name: "Lån og Spar Bank Sverige" },
49
50
  9640..9649 => { name: "Nordax Bank AB" },
50
51
  9650..9659 => { name: "MedMera Bank" },
@@ -23,8 +23,9 @@ module BankTools
23
23
  def errors
24
24
  errors = []
25
25
 
26
- errors << Errors::TOO_SHORT if serial_number.length < min_length
27
- errors << Errors::TOO_LONG if serial_number.length > max_length
26
+ # Validate the serial number as given, before any zero-filling.
27
+ errors << Errors::TOO_SHORT if raw_serial_number.length < min_length
28
+ errors << Errors::TOO_LONG if raw_serial_number.length > max_length
28
29
  errors << Errors::INVALID_CHARACTERS if number.to_s.match(/[^\d -]/)
29
30
 
30
31
  if luhn_for_serial?
@@ -63,17 +64,19 @@ module BankTools
63
64
  end
64
65
 
65
66
  def serial_number
66
- number = digits.slice(clearing_number_length..-1) || ""
67
-
68
67
  if zerofill?
69
- number.rjust(serial_number_length, "0")
68
+ raw_serial_number.rjust(Array(serial_number_length).last, "0")
70
69
  else
71
- number
70
+ raw_serial_number
72
71
  end
73
72
  end
74
73
 
75
74
  private
76
75
 
76
+ def raw_serial_number
77
+ digits.slice(clearing_number_length..-1) || ""
78
+ end
79
+
77
80
  def clearing_number_length
78
81
  checksum_for_clearing? ? 5 : 4
79
82
  end
@@ -1,5 +1,5 @@
1
1
  module BankTools
2
2
  module SE
3
- VERSION = "3.3.2"
3
+ VERSION = "3.4.0"
4
4
  end
5
5
  end
data/spec/account_spec.rb CHANGED
@@ -81,6 +81,14 @@ RSpec.describe BankTools::SE::Account do
81
81
  expect(BankTools::SE::Account.new("9570-2-00000000").errors).not_to include(BankTools::SE::Errors::TOO_SHORT)
82
82
  end
83
83
 
84
+ it "should include :too_short for Handelsbanken numbers shorter than 8 digits, even though they are zerofilled" do
85
+ expect(BankTools::SE::Account.new("6000-1234567").errors).to include(BankTools::SE::Errors::TOO_SHORT)
86
+ end
87
+
88
+ it "should include :too_long for Handelsbanken numbers longer than 9 digits" do
89
+ expect(BankTools::SE::Account.new("6000-1234567890").errors).to include(BankTools::SE::Errors::TOO_LONG)
90
+ end
91
+
84
92
  it "should include :too_long for numbers longer than the bank allows" do
85
93
  expect(BankTools::SE::Account.new("1100000000007").errors).to include(BankTools::SE::Errors::TOO_LONG)
86
94
  end
@@ -139,6 +147,10 @@ RSpec.describe BankTools::SE::Account do
139
147
  expect(BankTools::SE::Account.new("8000-2-0000000000").serial_number).to eq("0000000000")
140
148
  end
141
149
 
150
+ it "should zerofill Handelsbanken serial numbers to 9 digits" do
151
+ expect(BankTools::SE::Account.new("6000-12345678").serial_number).to eq("012345678")
152
+ end
153
+
142
154
  it "should be the empty string if there aren't enough numbers" do
143
155
  expect(BankTools::SE::Account.new("12").serial_number).to eq("")
144
156
  end
@@ -154,6 +166,11 @@ RSpec.describe BankTools::SE::Account do
154
166
  expect(BankTools::SE::Account.new("8000-2-0000000000").normalize).to eq("8000-2-0000000000")
155
167
  end
156
168
 
169
+ it "should zerofill Handelsbanken serial numbers to 9 digits" do
170
+ expect(BankTools::SE::Account.new("6000-12345678").normalize).to eq("6000-012345678")
171
+ expect(BankTools::SE::Account.new("6000-123456789").normalize).to eq("6000-123456789")
172
+ end
173
+
157
174
  it "should not attempt to normalize invalid numbers" do
158
175
  expect(BankTools::SE::Account.new(" 1-2-3 ").normalize).to eq(" 1-2-3 ")
159
176
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: banktools-se
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.2
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
@@ -45,7 +45,7 @@ licenses: []
45
45
  metadata:
46
46
  rubygems_mfa_required: 'true'
47
47
  source_code_uri: https://github.com/barsoom/banktools-se
48
- changelog_uri: https://github.com/barsoom/banktools-se/blob/v3.3.2/CHANGELOG.md
48
+ changelog_uri: https://github.com/barsoom/banktools-se/blob/v3.4.0/CHANGELOG.md
49
49
  rdoc_options: []
50
50
  require_paths:
51
51
  - lib
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 4.0.8
63
+ rubygems_version: 4.0.22
64
64
  specification_version: 4
65
65
  summary: Validate and normalize Swedish bank account numbers, plusgiro and bankgiro.
66
66
  test_files: []