nxt_support 0.6.3 → 0.7.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: df7d032c4cf505b1381021fb5118f9f2c71aee05eb1bdb4484915dc1aa9f78a8
4
- data.tar.gz: 2cdf4c3050bcd760bc5f17bae3f3e12e550b0726eb20047e3a485d7a26853b3e
3
+ metadata.gz: 7dd667ded531216f8bcfd88bdd112ee369bf1e5707b79263db64a76d6abfb15e
4
+ data.tar.gz: 91eba200463b8c381ee42eb40ce9e209e81d020d8027eaecb97e38ca03b8984b
5
5
  SHA512:
6
- metadata.gz: 52dad4f65484fc4b61cf6d0bdda7dab60d3b095a208f2c194d83f8254ef4bc9f1e49aee538bc2a3ab2fe1551c08cbd37e4dc6fa81a2f0a451d9a21475b818d7d
7
- data.tar.gz: 5baa5b0e528521f30a6cd0b92674ed535a3f3b2a6b3d63ef96b448390de87cfc2d7170deba87a3bf9c6d3a3ac28ce923eaaf03cfc1e1a12630b90e6a998fd8b0
6
+ metadata.gz: 49219628e5f0de43677bbbf04ac4518ec29226d0f4f9e86c164dddb72931d3349fd4f2a22400d3e976c595d94ee9568d26137dfdcb0b88ed6ccebbb4687cf284
7
+ data.tar.gz: a62a06f6809f429dd9bec2a88127c7709f78fe1b0dcd2a20d07efa34b0e129af91f70e7cd2788c45ae0554f10a99bd222b244a8b8d45d96758a3f40533042728
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v0.7.0 2026-09-16
2
+ - Added `NxtSupport::Iban`
3
+
1
4
  # v0.6.3 2026-08-11
2
5
  - Fix `Crystalizer#call` to return the resolved value from a custom `on_ambiguity` handler instead of always returning `unique_values.first`
3
6
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_support (0.6.3)
4
+ nxt_support (0.7.0)
5
5
  activerecord
6
6
  activesupport
7
7
  nxt_init
data/README.md CHANGED
@@ -360,6 +360,33 @@ NxtSupport::BirthDate.new(date: '1990-08-08').to_age # => 30
360
360
  NxtSupport::BirthDate.new(date: '1990-08-08').to_age_in_months # => 361
361
361
  ```
362
362
 
363
+ #### NxtSupport::Iban
364
+
365
+ `NxtSupport::Iban` normalizes IBANs into the form payment providers and comparisons expect: upcased, with all
366
+ whitespace removed. It does not validate the IBAN — anything that is not a string is returned unchanged.
367
+
368
+ ```ruby
369
+ NxtSupport::Iban.normalize('de89 3704 0044 0532 0130 00') # => "DE89370400440532013000"
370
+ NxtSupport::Iban.new(iban: 'de89 3704 0044 0532 0130 00').normalize # => "DE89370400440532013000"
371
+ ```
372
+
373
+ `#to_s`, `#country_code` and `#last4` all read from the normalized form, so they give the same answer no matter how
374
+ the IBAN was written. `#to_s` returns an empty string for a missing IBAN, while `#country_code` and `#last4` return
375
+ `nil` rather than an empty string.
376
+
377
+ ```ruby
378
+ iban = NxtSupport::Iban.new(iban: 'de89 3704 0044 0532 0130 00')
379
+
380
+ iban.to_s # => "DE89370400440532013000"
381
+ iban.country_code # => "DE"
382
+ iban.last4 # => "3000"
383
+ iban.redacted_s # => "DE****3000"
384
+ ```
385
+
386
+ Use `#redacted_s` wherever an IBAN would otherwise reach a log line, an error message or a support tool. It keeps the
387
+ country code and the last four characters and masks everything between them. When the IBAN is short enough that the
388
+ last four characters would give the rest away, they are masked too and only the country code remains.
389
+
363
390
  ### NxtSupport::Console.rake_cli_options
364
391
  A simple utility that uses Ruby's [OptionParser](https://docs.ruby-lang.org/en/2.1.0/OptionParser.html)
365
392
  to make it easier to pass CLI options to Rake tasks.
@@ -0,0 +1,43 @@
1
+ module NxtSupport
2
+ class Iban
3
+ require 'nxt_init'
4
+
5
+ include NxtInit
6
+ attr_init :iban
7
+
8
+ COUNTRY_CODE_LENGTH = 2
9
+ VISIBLE_CHARACTERS = 4
10
+ MASK = '****'.freeze
11
+
12
+ def self.normalize(iban)
13
+ new(iban: iban).normalize
14
+ end
15
+
16
+ def normalize
17
+ return iban unless iban.is_a?(String)
18
+
19
+ iban.upcase.gsub(/\s+/, '')
20
+ end
21
+
22
+ def to_s
23
+ normalize.to_s
24
+ end
25
+
26
+ def country_code
27
+ to_s.first(COUNTRY_CODE_LENGTH).presence
28
+ end
29
+
30
+ def last4
31
+ to_s.last(VISIBLE_CHARACTERS).presence
32
+ end
33
+
34
+ def redacted_s
35
+ normalized = to_s
36
+
37
+ return '' if normalized.empty?
38
+ return "#{country_code}#{MASK}" if normalized.length <= COUNTRY_CODE_LENGTH + VISIBLE_CHARACTERS
39
+
40
+ "#{country_code}#{MASK}#{last4}"
41
+ end
42
+ end
43
+ end
@@ -4,3 +4,4 @@ require_relative 'util/enum/value'
4
4
  require_relative 'util/hash_translator'
5
5
  require_relative 'util/crystalizer'
6
6
  require_relative 'util/birth_date'
7
+ require_relative 'util/iban'
@@ -1,3 +1,3 @@
1
1
  module NxtSupport
2
- VERSION = "0.6.3".freeze
2
+ VERSION = "0.7.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nxt_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nils Sommer
@@ -190,6 +190,7 @@ files:
190
190
  - lib/nxt_support/util/enum/value.rb
191
191
  - lib/nxt_support/util/enum_hash.rb
192
192
  - lib/nxt_support/util/hash_translator.rb
193
+ - lib/nxt_support/util/iban.rb
193
194
  - lib/nxt_support/version.rb
194
195
  - nxt_support.gemspec
195
196
  homepage: https://github.com/nxt-insurance/nxt_support