elfproef 0.1.4 → 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 +7 -0
- data/.travis.yml +2 -4
- data/README.md +19 -9
- data/lib/elfproef/bank_account_validator.rb +33 -3
- data/lib/elfproef/version.rb +1 -1
- data/spec/bank_account_validator_spec.rb +20 -0
- metadata +75 -82
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9ab3e58a3cab6c6c8ea36c8d0c4551af46785674
|
4
|
+
data.tar.gz: 4f6a5c6b02b9a1ae173fe6e7c27ad39a9fe1bf15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f4aef3dff74627d99f913cbb605100f7fc184066e38f04868636f3120cd3429c8c4096a9c00e5656664e98d3fcf02d08dab8742e7869e150a886657af714d66
|
7
|
+
data.tar.gz: cef822a4cfa414fecbb64aaf7d93c915b57808ecb3668ea5e7237190144ed118571e26a232bb9f68450fc13d9617231e41e260b616d8ec0bd6907cbef01fcdea
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
[](http://travis-ci.org/sytzeloor/elfproef)
|
4
4
|
|
5
|
-
|
5
|
+
## Features
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
* Validate international IBAN account numbers
|
8
|
+
* Validate Dutch BSN (Social Security) numbers (8 or 9 digits)
|
9
|
+
* Validates Dutch bank account numbers (9 or 10 digits)
|
10
|
+
* Allow for 1-7 digit ING bank account numbers
|
11
|
+
* Validate Dutch payment reference numbers (betalingskenmerken)
|
10
12
|
|
11
13
|
## Installation
|
12
14
|
|
@@ -22,27 +24,35 @@ and run
|
|
22
24
|
|
23
25
|
bundle install
|
24
26
|
|
27
|
+
## Compatibility
|
28
|
+
|
29
|
+
As of elfproef-0.2.0 you need ruby-1.9.3 or up, ruby-2.0.0 is preferred.
|
30
|
+
|
31
|
+
If your project is stuck at <= ruby-1.9.2, use the latest elfproef-0.1.x release.
|
32
|
+
|
33
|
+
gem 'elfproef', '0.1.4'
|
34
|
+
|
25
35
|
## Usage
|
26
36
|
|
27
|
-
Using the BsnValidator
|
37
|
+
Using the BsnValidator:
|
28
38
|
|
29
39
|
class User < ActiveRecord::Base
|
30
40
|
validates :bsn_number, bsn: true
|
31
41
|
end
|
32
42
|
|
33
|
-
Using the BankAccountValidator
|
43
|
+
Using the BankAccountValidator:
|
34
44
|
|
35
45
|
class User < ActiveRecord::Base
|
36
46
|
validates :account_number, bank_account: true
|
37
47
|
end
|
38
48
|
|
39
|
-
Using the PaymentReferenceValidator
|
49
|
+
Using the PaymentReferenceValidator:
|
40
50
|
|
41
51
|
class User < ActiveRecord::Base
|
42
52
|
validates :reference, payment_reference: true
|
43
53
|
end
|
44
54
|
|
45
|
-
You can also use these validators without `ActiveRecord` by including `ActiveModel::Validations
|
55
|
+
You can also use these validators without `ActiveRecord` by including `ActiveModel::Validations`:
|
46
56
|
|
47
57
|
class AwesomeDutchPerson
|
48
58
|
include ActiveModel::Validations
|
@@ -81,7 +91,7 @@ create a pull request.
|
|
81
91
|
|
82
92
|
## License
|
83
93
|
|
84
|
-
Copyright (c) 2012 Sytze Loor
|
94
|
+
Copyright (c) 2012-2013 Sytze Loor, Ariejan de Vroom
|
85
95
|
|
86
96
|
Permission is hereby granted, free of charge, to any person obtaining
|
87
97
|
a copy of this software and associated documentation files (the
|
@@ -19,15 +19,19 @@ class BankAccountValidator < ::ActiveModel::EachValidator
|
|
19
19
|
#
|
20
20
|
def self.validate_account_number(value, options = {})
|
21
21
|
number = value.to_s.gsub(/\D/, '').strip
|
22
|
-
|
23
22
|
# Not valid if length is 0, 8 or > 10
|
24
|
-
return false if number.length == 0 || number.length == 8 ||
|
23
|
+
return false if number.length == 0 || number.length == 8 || (value.length > 10 && value.length < 15) || value.length > 31
|
25
24
|
|
26
25
|
# ING account numbers
|
27
26
|
return true if (1..7).include?(number.length)
|
28
27
|
|
29
28
|
# Validate length 9 and 10 numbers as bank accounts
|
30
|
-
self.validate_with_eleven_test(number)
|
29
|
+
return true if self.validate_with_eleven_test(number) if (number.length == 9 || number.length == 10)
|
30
|
+
|
31
|
+
# If all other validations are failing, we are possibly dealing with an IBAN number
|
32
|
+
return true if self.validate_with_iban_test(value)
|
33
|
+
|
34
|
+
return false
|
31
35
|
end
|
32
36
|
|
33
37
|
private
|
@@ -57,4 +61,30 @@ class BankAccountValidator < ::ActiveModel::EachValidator
|
|
57
61
|
|
58
62
|
sum % 11 == 0
|
59
63
|
end
|
64
|
+
|
65
|
+
# Perform the mod-97 test (as described in ISO 7064)
|
66
|
+
# Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid.
|
67
|
+
# Move the four initial characters to the end of the string.
|
68
|
+
# Replace each letter in the string with two digits, thereby expanding the string, where A = 10, B = 11, ..., Z = 35.
|
69
|
+
# Interpret the string as a decimal integer and compute the remainder of that number on division by 97.
|
70
|
+
#
|
71
|
+
# If the remainder of the test equals 1, the IBAN is valid
|
72
|
+
def self.validate_with_iban_test(value)
|
73
|
+
country_prefix = to_ascii_code(value[0..3])
|
74
|
+
bank_code = to_ascii_code(value[4..7])
|
75
|
+
bank_number = value[8..value.length]
|
76
|
+
("#{bank_code}#{bank_number}#{country_prefix}".to_i % 97) == 1
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.to_ascii_code(value)
|
80
|
+
converted_value = ""
|
81
|
+
value.each_byte do |byte|
|
82
|
+
if (65..90).include?(byte)
|
83
|
+
converted_value += (byte - 55).to_s
|
84
|
+
else
|
85
|
+
converted_value += byte.chr
|
86
|
+
end
|
87
|
+
end
|
88
|
+
return converted_value
|
89
|
+
end
|
60
90
|
end
|
data/lib/elfproef/version.rb
CHANGED
@@ -66,6 +66,26 @@ describe BankAccountValidator do
|
|
66
66
|
subject.should be_valid
|
67
67
|
end
|
68
68
|
|
69
|
+
it 'accepts a Dutch IBAN bank account number' do
|
70
|
+
subject.account = 'NL91ABNA0417164300'
|
71
|
+
subject.should be_valid
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'accepts a German IBAN bank account number' do
|
75
|
+
subject.account = 'DE89370400440532013000'
|
76
|
+
subject.should be_valid
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'accepts a Belgium IBAN bank account number' do
|
80
|
+
subject.account = 'BE68539007547034'
|
81
|
+
subject.should be_valid
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'rejects an invalid iban bank account' do
|
85
|
+
subject.account = 'NL11ABNA1111111'
|
86
|
+
subject.should_not be_valid
|
87
|
+
end
|
88
|
+
|
69
89
|
it "rejects on an 8 digit number" do
|
70
90
|
subject.account = "12345678"
|
71
91
|
subject.should_not be_valid
|
metadata
CHANGED
@@ -1,82 +1,81 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: elfproef
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 4
|
9
|
-
version: 0.1.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Sytze Loor
|
13
8
|
- Ariejan de Vroom
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rake
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
version: "0"
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
31
21
|
type: :development
|
32
|
-
version_requirements: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: rspec
|
35
22
|
prerelease: false
|
36
|
-
|
37
|
-
requirements:
|
38
|
-
- -
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
|
41
|
-
|
42
|
-
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
43
35
|
type: :development
|
44
|
-
version_requirements: *id002
|
45
|
-
- !ruby/object:Gem::Dependency
|
46
|
-
name: guard-rspec
|
47
36
|
prerelease: false
|
48
|
-
|
49
|
-
requirements:
|
50
|
-
- -
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
|
53
|
-
|
54
|
-
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: guard-rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
55
49
|
type: :development
|
56
|
-
version_requirements: *id003
|
57
|
-
- !ruby/object:Gem::Dependency
|
58
|
-
name: activemodel
|
59
50
|
prerelease: false
|
60
|
-
|
61
|
-
requirements:
|
62
|
-
- -
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
|
65
|
-
|
66
|
-
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: activemodel
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
67
63
|
type: :runtime
|
68
|
-
|
69
|
-
|
70
|
-
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: Validation for Dutch bank account numbers, Citizen Service Numbers (BSN)
|
71
|
+
and Payment reference
|
72
|
+
email:
|
71
73
|
- sytze@tweedledum.nl
|
72
74
|
- ariejan@ariejan.net
|
73
75
|
executables: []
|
74
|
-
|
75
76
|
extensions: []
|
76
|
-
|
77
77
|
extra_rdoc_files: []
|
78
|
-
|
79
|
-
files:
|
78
|
+
files:
|
80
79
|
- .gitignore
|
81
80
|
- .travis.yml
|
82
81
|
- Gemfile
|
@@ -93,37 +92,31 @@ files:
|
|
93
92
|
- spec/bsn_validator_spec.rb
|
94
93
|
- spec/payment_reference_validator_spec.rb
|
95
94
|
- spec/spec_helper.rb
|
96
|
-
has_rdoc: true
|
97
95
|
homepage: https://github.com/sytzeloor/elfproef
|
98
96
|
licenses: []
|
99
|
-
|
97
|
+
metadata: {}
|
100
98
|
post_install_message:
|
101
99
|
rdoc_options: []
|
102
|
-
|
103
|
-
require_paths:
|
100
|
+
require_paths:
|
104
101
|
- lib
|
105
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- -
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
segments:
|
117
|
-
- 0
|
118
|
-
version: "0"
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
119
112
|
requirements: []
|
120
|
-
|
121
113
|
rubyforge_project: elfproef
|
122
|
-
rubygems_version:
|
114
|
+
rubygems_version: 2.0.3
|
123
115
|
signing_key:
|
124
|
-
specification_version:
|
125
|
-
summary: Validation for Dutch bank account numbers, Citizen Service Numbers (BSN)
|
126
|
-
|
116
|
+
specification_version: 4
|
117
|
+
summary: Validation for Dutch bank account numbers, Citizen Service Numbers (BSN)
|
118
|
+
and Payment reference
|
119
|
+
test_files:
|
127
120
|
- spec/bank_account_validator_spec.rb
|
128
121
|
- spec/bsn_validator_spec.rb
|
129
122
|
- spec/payment_reference_validator_spec.rb
|