bicvalidator 0.1.2 → 0.1.3
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/README.md +1 -1
- data/Rakefile +3 -0
- data/bicvalidator.gemspec +3 -2
- data/lib/bicvalidator/version.rb +1 -1
- data/lib/bicvalidator.rb +80 -135
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82d4b194fd9542db105f28417793c1ab7509596a
|
4
|
+
data.tar.gz: ae7994ca2142ed3d6215fa0cfeb165bcc009b6de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faba57f7de958b26b323fbabd57c3d473d799ba6454d9b7b2c377d8ba3af533a3ff52b846d4224658e08c27e4da2e34c147f32c5df8f7c0c54db72b7327e891b
|
7
|
+
data.tar.gz: c52eecde0d93095dc6c2c2df32d54e2a8db1272f01b1f4c28f029aabfd7f1e6a7c71a4b726cb4cc03699852f82b034e21e152e3fbb9ff452995f5a0c5cc3c583
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/bicvalidator.gemspec
CHANGED
@@ -33,10 +33,11 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_development_dependency "bundler", "~> 1.15"
|
34
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
35
35
|
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
-
|
36
|
+
#A Ruby library for testing your library against different versions of dependencie
|
37
|
+
spec.add_development_dependency 'appraisal'
|
37
38
|
|
38
39
|
#for mattr_accessor, reverse_merge
|
39
|
-
spec.add_dependency "activesupport"
|
40
|
+
spec.add_dependency "activesupport"
|
40
41
|
|
41
42
|
#laender
|
42
43
|
#Countries is a collection of all sorts of useful information for every country in the ISO 3166 standard.
|
data/lib/bicvalidator/version.rb
CHANGED
data/lib/bicvalidator.rb
CHANGED
@@ -5,155 +5,100 @@ require 'active_support/core_ext'
|
|
5
5
|
require 'countries'
|
6
6
|
|
7
7
|
module Bicvalidator
|
8
|
-
|
9
|
-
mattr_accessor :sepa_bic_countries
|
8
|
+
|
9
|
+
mattr_accessor :sepa_bic_countries
|
10
10
|
|
11
|
-
##https://wiki.xmldation.com/Support/EPC/List_of_SEPA_countries
|
12
|
-
#kann ich somit in einem initailizer wieder ueberschreiben
|
13
11
|
Bicvalidator.sepa_bic_countries = ["AT", "BE", "BG", "CH", "CY", "CZ", "DE", "DK", "EE", "ES", "FI", "FR", "GB", "GR", "HR", "HU", "IE", "IT", "LI", "LT", "LU", "LV", "MC", "MT", "NL", "NO", "PL", "PT", "RO", "SE", "SI", "SK", "SM", "GI", "GF", "GP", "GG", "IS", "IM", "JE", "MQ", "YT", "RE", "BL", "MF", "PM"]
|
14
12
|
|
15
13
|
|
16
|
-
class
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
14
|
+
class Bic
|
15
|
+
|
16
|
+
attr_accessor :bic_code, :bank, :country, :location, :branch
|
17
|
+
|
18
|
+
def initialize(bic_str)
|
19
|
+
##strip reicht nicht denn strip entfernt nur leerzeichen vorne und hinten
|
20
|
+
@bic_code = bic_str.strip.gsub(/\s+/, '').upcase
|
21
|
+
end
|
22
|
+
|
23
|
+
def errorcode
|
24
|
+
return if valid?
|
25
|
+
return "BV0010" if !has_valid_lenght?
|
26
|
+
return "BV0011" if !has_valid_format?
|
27
|
+
return "BV0012" if !valid_country_code?
|
28
|
+
return "BV0013" if !valid_location_code?
|
29
|
+
return "BV0014" if !valid_branch_code?
|
30
|
+
end
|
31
|
+
#in instanz
|
32
|
+
def valid?
|
33
|
+
has_valid_lenght? && has_valid_format? && valid_country_code? && valid_location_code? && valid_branch_code?
|
34
|
+
end
|
35
|
+
|
36
|
+
def has_valid_lenght?
|
37
|
+
[8, 11].include? @bic_code.length
|
38
|
+
end
|
39
|
+
|
40
|
+
def has_valid_format?
|
41
|
+
!(@bic_code =~ bic_iso_format).nil?
|
30
42
|
end
|
31
43
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
@bic_bankcode = @options[:bic_bankcode].blank? ? nil : @options[:bic_bankcode]
|
36
|
-
@bic_country = @options[:bic_country].blank? ? nil : @options[:bic_country]
|
37
|
-
|
38
|
-
|
39
|
-
if [@bic_code,@bic_bankcode,@bic_country].all? {|x| x.nil?}
|
40
|
-
@errorcode = "BV0000"
|
41
|
-
return
|
42
|
-
end
|
43
|
-
|
44
|
-
@sepa_country_check = @options[:sepa_country_check]
|
45
|
-
|
46
|
-
if @bic_code
|
47
|
-
#strip reicht nicht denn strip entfernt nur leerzeichen vorne und hinten
|
48
|
-
@bic_code = self.canonicalize_str(@bic_code)
|
49
|
-
|
50
|
-
#invalid character
|
51
|
-
if (@bic_code =~ /^[A-Z0-9]+$/).nil?
|
52
|
-
@bic_code = nil
|
53
|
-
@errorcode = "BV0010"
|
54
|
-
return
|
55
|
-
end
|
56
|
-
|
57
|
-
#muss 8 oder 11 stellen haben
|
58
|
-
case @bic_code.length
|
59
|
-
when 8
|
60
|
-
#wir furllen immer mit XXX auf 11 Stellen auf
|
61
|
-
@bic_code = "#{@bic_code}XXX"
|
62
|
-
when 11
|
63
|
-
|
64
|
-
else
|
65
|
-
@bic_code = nil
|
66
|
-
@errorcode = "BV0011"
|
67
|
-
return
|
68
|
-
end
|
69
|
-
#wir setzen bic_country auf die 4+5 Stelle des der BIC
|
70
|
-
@bic_country = @bic_code[4..5]
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
#egal ob durch biccode gesetzt oder das land ubergeben wurde immer st checkn ob da was geht
|
75
|
-
if @bic_country
|
76
|
-
#strip reicht nicht denn strip entfernt nur leerzeichen vorne und hinten
|
77
|
-
@bic_country = self.canonicalize_str(@bic_country)
|
78
|
-
|
79
|
-
if @bic_country.length != 2
|
80
|
-
@bic_country = nil
|
81
|
-
@errorcode = "BV0020"
|
82
|
-
return
|
83
|
-
end
|
84
|
-
if (@bic_country =~ /^[A-Z]+$/).nil?
|
85
|
-
@bic_country = nil
|
86
|
-
@errorcode = "BV0021"
|
87
|
-
return
|
88
|
-
end
|
89
|
-
|
90
|
-
#gibts das land uberhaupt zb wenn ZZ kommt
|
91
|
-
if ISO3166::Country.new("#{@bic_country}").nil?
|
92
|
-
@bic_country = nil
|
93
|
-
@errorcode = "BV0025"
|
94
|
-
return
|
95
|
-
end
|
96
|
-
|
97
|
-
if Bicvalidator.sepa_bic_countries.include? @bic_country
|
98
|
-
@sepa_country = true
|
99
|
-
end
|
100
|
-
|
101
|
-
if @sepa_country_check and !@sepa_country
|
102
|
-
@errorcode = "BV0026"
|
103
|
-
return
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
if @bic_bankcode
|
109
|
-
|
110
|
-
if !@bic_country
|
111
|
-
#bankcode ohne land geht nicht
|
112
|
-
@errorcode = "BV0030"
|
113
|
-
return
|
114
|
-
end
|
115
|
-
|
116
|
-
#strip reicht nicht denn strip entfernt nur leerzeichen vorne und hinten
|
117
|
-
@bic_bankcode = self.canonicalize_str(@bic_bankcode)
|
118
|
-
|
119
|
-
#es duerfen nur A-Z und 0-9 kommne, keine Sonderzeichen
|
120
|
-
if (@bic_bankcode =~ /^[A-Z0-9]+$/).nil?
|
121
|
-
@bic_bankcode = nil
|
122
|
-
@errorcode = "BV0032"
|
123
|
-
return
|
124
|
-
end
|
125
|
-
|
126
|
-
return if !["DE","AT","ES","CH"].include? @bic_country
|
127
|
-
|
128
|
-
#kontonummer in DE 8 stellig
|
129
|
-
case @bic_country
|
130
|
-
when "AT","CH"
|
131
|
-
#kontonummer in AT 5 stellig Zahlen
|
132
|
-
rule = '^[0-9]{5}$'
|
133
|
-
when "DE","ES"
|
134
|
-
#kontonummer in DE 8 stellig Zahlen
|
135
|
-
rule = '^[0-9]{8}$'
|
136
|
-
end
|
137
|
-
|
138
|
-
if regexp = Regexp.new(rule).match(@bic_bankcode)
|
139
|
-
#hat er gefunden
|
140
|
-
else
|
141
|
-
@bic_bankcode = nil
|
142
|
-
@errorcode = "BV0040"
|
143
|
-
return
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|
44
|
+
def valid_country_code?
|
45
|
+
!ISO3166::Country.new(country).nil?
|
46
|
+
end
|
147
47
|
|
48
|
+
def valid_location_code?
|
49
|
+
#http://de.wikipedia.org/wiki/ISO_9362
|
50
|
+
#2-stellige Codierung des Ortes in zwei Zeichen. Das erste Zeichen darf nicht die Ziffer „0“ oder „1“ sein.
|
51
|
+
#Der Buchstabe 'O' ist als zweites Zeichen nicht gestattet.
|
52
|
+
!(location[0] =~ /[^01]/ && location[1] =~ /[^O]/).nil?
|
53
|
+
end
|
148
54
|
|
55
|
+
def valid_branch_code?
|
56
|
+
#Der Branch-Code darf nicht mit „X“ anfangen, es sei denn, es ist „XXX“.
|
57
|
+
return true if @bic_code.length == 8
|
58
|
+
return true if branch == "XXX"
|
59
|
+
(branch[0] =~ /[X]/).nil?
|
149
60
|
end
|
150
61
|
|
62
|
+
def sepa_scheme?
|
63
|
+
valid? and Bicvalidator.sepa_bic_countries.include? country
|
64
|
+
end
|
151
65
|
|
152
66
|
|
153
|
-
def
|
154
|
-
|
67
|
+
def bank
|
68
|
+
@bank ||= match[1]
|
155
69
|
end
|
156
70
|
|
71
|
+
def country
|
72
|
+
@country ||= match[2]
|
73
|
+
end
|
74
|
+
|
75
|
+
def location
|
76
|
+
@location ||= match[3]
|
77
|
+
end
|
78
|
+
|
79
|
+
def branch
|
80
|
+
@branch ||= match[4]
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def bic_iso_format
|
86
|
+
#https://de.wikipedia.org/wiki/ISO_9362
|
87
|
+
#BBBB 4-stelliger Bankcode, vom Geldinstitut frei wählbar
|
88
|
+
#CC 2-stelliger Ländercode nach ISO 3166-1
|
89
|
+
#LL 2-stellige Codierung des Ortes in zwei Zeichen.
|
90
|
+
#Das erste Zeichen darf nicht die Ziffer „0“ oder „1“ sein.
|
91
|
+
#Wenn das zweite Zeichen kein Buchstabe, sondern eine Ziffer ist, so bedeutet dies:
|
92
|
+
#bbb 3-stellige Kennzeichnung (Branch-Code) der Filiale oder Abteilung (optional)
|
93
|
+
#test in http://rubular.com/
|
94
|
+
/([A-Z]{4})([A-Z]{2})([0-9A-Z]{2})([0-9A-Z]{3})?/
|
95
|
+
end
|
96
|
+
|
97
|
+
def match
|
98
|
+
bic_iso_format.match(@bic_code)
|
99
|
+
end
|
100
|
+
|
101
|
+
|
157
102
|
end
|
158
103
|
|
159
104
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bicvalidator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olaf Kaderka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,20 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: appraisal
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: activesupport
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '0'
|
62
76
|
type: :runtime
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: countries
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|