ibanvalidator 0.1.5 → 0.2.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/README.md +15 -1
- data/ibanvalidator.gemspec +3 -1
- data/lib/ibanvalidator.rb +7 -0
- data/lib/ibanvalidator/iban.rb +23 -13
- data/lib/ibanvalidator/iban_model_validator.rb +12 -0
- data/lib/ibanvalidator/version.rb +1 -1
- data/lib/locales/de.yml +10 -0
- data/lib/locales/en.yml +10 -0
- metadata +18 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef40528d9257eeb9f757f077d3dcb48528705306
|
4
|
+
data.tar.gz: d0df34bcb21e7fa0260a2eb7aa4413caae0cd2a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4774641ad2a413d328b64b5a6e8589d6ab35bfed46e337e6518c215dfbcb96429492d63e32a29f2b6f91b594f87f533e9f30119dee97d7b622027fcff6fe5eef
|
7
|
+
data.tar.gz: 3f9c45b458d1c313b162631e0cc153dfce61d965786f3dfe19b922aef3729b9cb072c9a1bb15283a227f59cfc9fca5145bca3455aa00e3b91ab6e1b28b492d95
|
data/README.md
CHANGED
@@ -32,6 +32,7 @@ Or install it yourself as:
|
|
32
32
|
### advanced
|
33
33
|
require 'ibanvalidator'
|
34
34
|
iban = Ibanvalidator::IBAN.new("DE89370 40044053201 3000")
|
35
|
+
iban.valid? => true
|
35
36
|
iban.code => "DE89370400440532013000"
|
36
37
|
iban.bban => "370400440532013000"
|
37
38
|
iban.country_code => "DE"
|
@@ -48,7 +49,20 @@ Or install it yourself as:
|
|
48
49
|
|
49
50
|
**Ibanvalidator.sepa_countries** liefert alle Länder die im Sepa Raum liegen
|
50
51
|
|
51
|
-
|
52
|
+
### ActiveRecord/Model Validator
|
53
|
+
Man kann auch den Model Validator einbinden. Die Felhermeldung sind übersetzt in deutsch und englisch siehe /locales
|
54
|
+
|
55
|
+
validates :iban, iban_model: true
|
56
|
+
de:
|
57
|
+
errors:
|
58
|
+
messages:
|
59
|
+
iban_too_short: zu wenig Zeichen
|
60
|
+
iban_too_long: zu viel Zeichen
|
61
|
+
iban_bad_chars: ungültige Zeichen
|
62
|
+
iban_unknown_country_code: Land nicht unterstütz
|
63
|
+
iban_bad_length: falsche Länge
|
64
|
+
iban_bad_format: Formatfehler
|
65
|
+
iban_bad_check_digits: falsche Kontrollziffer
|
52
66
|
|
53
67
|
|
54
68
|
|
data/ibanvalidator.gemspec
CHANGED
data/lib/ibanvalidator.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'active_support/core_ext'
|
3
|
+
require 'active_model'
|
4
|
+
|
3
5
|
require "ibanvalidator/version"
|
4
6
|
require 'ibanvalidator/conversion.rb'
|
5
7
|
require 'ibanvalidator/iban.rb'
|
6
8
|
require 'ibanvalidator/iban_rules.rb'
|
9
|
+
require 'ibanvalidator/iban_model_validator.rb'
|
7
10
|
|
8
11
|
module Ibanvalidator
|
9
12
|
mattr_accessor :default_rules #all rules from yaml file 'rules'
|
@@ -32,3 +35,7 @@ module Ibanvalidator
|
|
32
35
|
|
33
36
|
|
34
37
|
end
|
38
|
+
|
39
|
+
ActiveModel::Validations.send(:include, Ibanvalidator)
|
40
|
+
I18n.load_path += Dir[File.expand_path(File.join(File.dirname(__FILE__),'/locales', '*.yml')).to_s]
|
41
|
+
|
data/lib/ibanvalidator/iban.rb
CHANGED
@@ -2,12 +2,26 @@
|
|
2
2
|
module Ibanvalidator
|
3
3
|
class IBAN
|
4
4
|
|
5
|
-
|
5
|
+
attr_accessor :errors
|
6
|
+
|
7
|
+
#quick_check Ibanvalidator::IBAN.valid?("DE89370400440532013000")
|
8
|
+
def self.valid?( code, rules = nil )
|
9
|
+
new(code).valid?(rules)
|
10
|
+
end
|
6
11
|
|
7
12
|
def initialize( code )
|
8
13
|
@code = IBAN.canonicalize_code(code)
|
9
14
|
end
|
10
15
|
|
16
|
+
def errors(rules = nil)
|
17
|
+
@errors ||= self.validation_errors(rules)
|
18
|
+
end
|
19
|
+
|
20
|
+
#instanz
|
21
|
+
def valid?(rules = nil)
|
22
|
+
errors(rules).empty?
|
23
|
+
end
|
24
|
+
|
11
25
|
# The code in canonical form,
|
12
26
|
# suitable for storing in a database
|
13
27
|
# or sending over the wire
|
@@ -27,15 +41,12 @@ module Ibanvalidator
|
|
27
41
|
@code[4..-1]
|
28
42
|
end
|
29
43
|
|
44
|
+
|
30
45
|
def sepa_scheme?
|
31
46
|
Ibanvalidator.sepa_countries.include? country_code
|
32
47
|
end
|
33
48
|
|
34
49
|
|
35
|
-
def self.valid?( code, rules = nil )
|
36
|
-
new(code).validation_errors(rules).empty?
|
37
|
-
end
|
38
|
-
|
39
50
|
def self.canonicalize_code( code )
|
40
51
|
code.to_s.strip.gsub(/\s+/, '').upcase
|
41
52
|
end
|
@@ -65,24 +76,23 @@ module Ibanvalidator
|
|
65
76
|
|
66
77
|
def validation_errors( rules = nil )
|
67
78
|
errors = []
|
68
|
-
return [:
|
69
|
-
return [:
|
70
|
-
return [:
|
79
|
+
return [:iban_too_short] if @code.size < 5
|
80
|
+
return [:iban_too_long] if @code.size > 34
|
81
|
+
return [:iban_bad_chars] unless @code =~ /^[A-Z0-9]+$/
|
71
82
|
errors += validation_errors_against_rules( rules || Ibanvalidator.default_rules )
|
72
|
-
errors << :
|
83
|
+
errors << :iban_bad_check_digits unless valid_check_digits?
|
73
84
|
errors
|
74
85
|
end
|
75
86
|
|
76
87
|
|
77
88
|
def validation_errors_against_rules( rules )
|
78
89
|
errors = []
|
79
|
-
return [:
|
80
|
-
errors << :
|
81
|
-
errors << :
|
90
|
+
return [:iban_unknown_country_code] if rules[country_code].nil?
|
91
|
+
errors << :iban_bad_length if rules[country_code]["length"] != @code.size
|
92
|
+
errors << :iban_bad_format unless bban =~ rules[country_code]["bban_pattern"]
|
82
93
|
errors
|
83
94
|
end
|
84
95
|
|
85
|
-
|
86
96
|
########### Pruefdsummen siehe https://de.wikipedia.org/wiki/IBAN#Validierung_der_Pr.C3.BCfsum
|
87
97
|
#Nun wird der Rest berechnet, der sich beim ganzzahligen Teilen der Zahl durch 97 ergibt (Modulo 97).
|
88
98
|
def valid_check_digits?
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Ibanvalidator
|
2
|
+
class IbanModelValidator < ActiveModel::EachValidator
|
3
|
+
def validate_each(record, attribute, value)
|
4
|
+
iban = Ibanvalidator::IBAN.new(value)
|
5
|
+
if !iban.valid?
|
6
|
+
iban.errors.each do |error|
|
7
|
+
record.errors.add attribute, error.to_sym
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/locales/de.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
de:
|
2
|
+
errors:
|
3
|
+
messages:
|
4
|
+
iban_too_short: zu wenig Zeichen
|
5
|
+
iban_too_long: zu viel Zeichen
|
6
|
+
iban_bad_chars: ungültige Zeichen
|
7
|
+
iban_unknown_country_code: Land nicht unterstütz
|
8
|
+
iban_bad_length: falsche Länge
|
9
|
+
iban_bad_format: Formatfehler
|
10
|
+
iban_bad_check_digits: falsche Kontrollziffer
|
data/lib/locales/en.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
en:
|
2
|
+
errors:
|
3
|
+
messages:
|
4
|
+
iban_too_short: too_short
|
5
|
+
iban_too_long: too_long
|
6
|
+
iban_bad_chars: bad characters
|
7
|
+
iban_unknown_country_code: country not supported
|
8
|
+
iban_bad_length: bad length
|
9
|
+
iban_bad_format: fromat error
|
10
|
+
iban_bad_check_digits: bad check digit
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibanvalidator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olaf Kaderka
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activemodel
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: ''
|
70
84
|
email:
|
71
85
|
- okaderka@yahoo.de
|
@@ -88,9 +102,12 @@ files:
|
|
88
102
|
- lib/ibanvalidator/conversion.rb
|
89
103
|
- lib/ibanvalidator/conversion_rules.yml
|
90
104
|
- lib/ibanvalidator/iban.rb
|
105
|
+
- lib/ibanvalidator/iban_model_validator.rb
|
91
106
|
- lib/ibanvalidator/iban_rules.rb
|
92
107
|
- lib/ibanvalidator/rules.yml
|
93
108
|
- lib/ibanvalidator/version.rb
|
109
|
+
- lib/locales/de.yml
|
110
|
+
- lib/locales/en.yml
|
94
111
|
homepage: https://github.com/olafkaderka/ibanvalidator
|
95
112
|
licenses:
|
96
113
|
- MIT
|