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 +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +27 -0
- data/lib/nxt_support/util/iban.rb +43 -0
- data/lib/nxt_support/util.rb +1 -0
- data/lib/nxt_support/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7dd667ded531216f8bcfd88bdd112ee369bf1e5707b79263db64a76d6abfb15e
|
|
4
|
+
data.tar.gz: 91eba200463b8c381ee42eb40ce9e209e81d020d8027eaecb97e38ca03b8984b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 49219628e5f0de43677bbbf04ac4518ec29226d0f4f9e86c164dddb72931d3349fd4f2a22400d3e976c595d94ee9568d26137dfdcb0b88ed6ccebbb4687cf284
|
|
7
|
+
data.tar.gz: a62a06f6809f429dd9bec2a88127c7709f78fe1b0dcd2a20d07efa34b0e129af91f70e7cd2788c45ae0554f10a99bd222b244a8b8d45d96758a3f40533042728
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
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
|
data/lib/nxt_support/util.rb
CHANGED
data/lib/nxt_support/version.rb
CHANGED
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.
|
|
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
|