elfproef 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -1
- data/elfproef.gemspec +2 -2
- data/lib/elfproef/payment_reference_validator.rb +87 -0
- data/lib/elfproef/version.rb +1 -1
- data/lib/elfproef.rb +1 -0
- data/spec/bank_account_validator_spec.rb +15 -5
- data/spec/payment_reference_validator_spec.rb +77 -0
- metadata +84 -63
data/README.md
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/sytzeloor/elfproef.png?branch=master)](http://travis-ci.org/sytzeloor/elfproef)
|
4
4
|
|
5
|
-
This gem adds
|
5
|
+
This gem adds three validators to your arsenal:
|
6
6
|
|
7
7
|
* BsnValidator will validate Burgerservicenummers (Dutch social security numbers). It accepts both 8 and 9 digit BSN numbers.
|
8
8
|
* BankAccountValidator will validate ING accounts (1-7 digits), and 9 or 10 digit bank account numbers using the elven-test.
|
9
|
+
* PaymentReferenceValidator will validate betalingskenmerken (Dutch payment reference numbers) using a weighted modulus 11 and a length check.
|
9
10
|
|
10
11
|
## Installation
|
11
12
|
|
@@ -35,6 +36,12 @@ Using the BankAccountValidator
|
|
35
36
|
validates :account_number, bank_account: true
|
36
37
|
end
|
37
38
|
|
39
|
+
Using the PaymentReferenceValidator
|
40
|
+
|
41
|
+
class User < ActiveRecord::Base
|
42
|
+
validates :reference, payment_reference: true
|
43
|
+
end
|
44
|
+
|
38
45
|
You can also use these validators without `ActiveRecord` by including `ActiveModel::Validations`.
|
39
46
|
|
40
47
|
class AwesomeDutchPerson
|
@@ -55,6 +62,7 @@ Add the following to your locale file:
|
|
55
62
|
ATTRIBUTE:
|
56
63
|
invalid_bank_account: "is not a valid bank account number"
|
57
64
|
invalid_bsn: "is not a valid BSN"
|
65
|
+
invalid_payment_reference: "is not a valid payment reference"
|
58
66
|
|
59
67
|
## Bugs / Feature Requests
|
60
68
|
|
data/elfproef.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Sytze Loor", "Ariejan de Vroom"]
|
9
9
|
s.email = ["sytze@tweedledum.nl", "ariejan@ariejan.net"]
|
10
10
|
s.homepage = "https://github.com/sytzeloor/elfproef"
|
11
|
-
s.summary = %q{Validation for Dutch bank account numbers
|
12
|
-
s.description = %q{Validation for Dutch bank account numbers
|
11
|
+
s.summary = %q{Validation for Dutch bank account numbers, Citizen Service Numbers (BSN) and Payment reference}
|
12
|
+
s.description = %q{Validation for Dutch bank account numbers, Citizen Service Numbers (BSN) and Payment reference}
|
13
13
|
|
14
14
|
s.rubyforge_project = "elfproef"
|
15
15
|
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'active_model/validator'
|
2
|
+
require 'active_support/concern'
|
3
|
+
|
4
|
+
# Validates if the specified value is a valid
|
5
|
+
# payment reference number using a weighted modulus 11
|
6
|
+
class PaymentReferenceValidator < ::ActiveModel::EachValidator
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
unless self.class.validate_payment_reference(value, options)
|
11
|
+
record.errors.add(attribute, :invalid_payment_reference, options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Takes the payment reference number and returns true if:
|
16
|
+
#
|
17
|
+
# * The number is exact 7 digits (no verification is possible)
|
18
|
+
# * Is between 9 and 14 digits, has the correct check digit and has the correct length digit
|
19
|
+
# * Is exact 16 digits and has the correct check digit
|
20
|
+
#
|
21
|
+
def self.validate_payment_reference(value, options = {})
|
22
|
+
number = value.to_s.gsub(/\D/, '').strip
|
23
|
+
|
24
|
+
# Not valid if payment reference length is < 7, 8, 15 or > 16
|
25
|
+
return false if number.length < 7 || number.length == 8 || number.length == 15 || number.length > 16
|
26
|
+
|
27
|
+
# No further verification possible for 7 digit payment references
|
28
|
+
return true if number.length == 7
|
29
|
+
|
30
|
+
# For payment references between 9 and 14 digits validate it has the correct length digit
|
31
|
+
self.validate_length_digit(number) if (9..14).include?(number.length)
|
32
|
+
|
33
|
+
# Validate the check digit
|
34
|
+
self.validate_check_digit(number)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# Validates the length digit. This is the second digit when
|
40
|
+
# a payment reference is between 9 and 14 digits
|
41
|
+
#
|
42
|
+
# Possible values:
|
43
|
+
# 7 for a 9-digit payment reference
|
44
|
+
# 8 for a 10-digit payment reference
|
45
|
+
# 9 for a 11-digit payment reference
|
46
|
+
# 0 for a 12-digit payment reference
|
47
|
+
# 1 for a 13-digit payment reference
|
48
|
+
# 2 for a 14-digit payment reference
|
49
|
+
#
|
50
|
+
def self.validate_length_digit(number)
|
51
|
+
number[1].chr.to_i == number.length - (number.length > 11 ? 12 : 2)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Validates the check digit. This is the first digit when a payment
|
55
|
+
# reference is between 9 and 14 digits or is exact 16 digits
|
56
|
+
#
|
57
|
+
# The check digit is calculated using a weighted modulus 11:
|
58
|
+
#
|
59
|
+
# c123456789012345
|
60
|
+
# ABCDEFGHIJKLMNO
|
61
|
+
#
|
62
|
+
# sum = 10*A + 5*B + 8*C + 4*D + 2*E + 1*F + 6*G + 3*H + 7*I + 9*J + 10*K + 5*L + 8*M + 4*N + 2*O
|
63
|
+
# c = 11 - (sum % 11)
|
64
|
+
#
|
65
|
+
# The check digit is equal to c, with two exceptions. The check digit is
|
66
|
+
# 0 when c == 10
|
67
|
+
# 1 when c == 11
|
68
|
+
def self.validate_check_digit(number)
|
69
|
+
# Remove the first digit (check digit) from the payment reference.
|
70
|
+
# To calculate the sum we need a 15 digit payment reference,
|
71
|
+
# prefix with 0 if necessary.
|
72
|
+
reference = number[1..-1].rjust(15,"0").split("")
|
73
|
+
weights = [10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
|
74
|
+
|
75
|
+
# Calculate the sum
|
76
|
+
sum = 0
|
77
|
+
i = 0
|
78
|
+
while i < 15
|
79
|
+
sum += reference[i].to_i * weights[i]
|
80
|
+
i += 1
|
81
|
+
end
|
82
|
+
check_digit = 11 - (sum % 11)
|
83
|
+
check_digit -= 10 if check_digit >= 10
|
84
|
+
|
85
|
+
number[0].chr.to_i == check_digit
|
86
|
+
end
|
87
|
+
end
|
data/lib/elfproef/version.rb
CHANGED
data/lib/elfproef.rb
CHANGED
@@ -22,27 +22,37 @@ describe BankAccountValidator do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "accepts 3 digit ING accounts" do
|
25
|
-
subject.account = "
|
25
|
+
subject.account = "123"
|
26
26
|
subject.should be_valid
|
27
27
|
end
|
28
28
|
|
29
29
|
it "accepts 4 digit ING accounts" do
|
30
|
-
subject.account = "
|
30
|
+
subject.account = "1234"
|
31
31
|
subject.should be_valid
|
32
32
|
end
|
33
33
|
|
34
34
|
it "accepts 5 digit ING accounts" do
|
35
|
-
subject.account = "
|
35
|
+
subject.account = "12345"
|
36
36
|
subject.should be_valid
|
37
37
|
end
|
38
38
|
|
39
39
|
it "accepts 6 digit ING accounts" do
|
40
|
-
subject.account = "
|
40
|
+
subject.account = "123456"
|
41
41
|
subject.should be_valid
|
42
42
|
end
|
43
43
|
|
44
44
|
it "accepts 7 digit ING accounts" do
|
45
|
-
subject.account = "
|
45
|
+
subject.account = "1234567"
|
46
|
+
subject.should be_valid
|
47
|
+
end
|
48
|
+
|
49
|
+
it "accepts P-prefixed ING accounts" do
|
50
|
+
subject.account = "P123"
|
51
|
+
subject.should be_valid
|
52
|
+
end
|
53
|
+
|
54
|
+
it "accepts P-prefixed ING accounts with 7 digits" do
|
55
|
+
subject.account = "P1234567"
|
46
56
|
subject.should be_valid
|
47
57
|
end
|
48
58
|
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class PaymentReferenceTest
|
4
|
+
include ActiveModel::Validations
|
5
|
+
attr_accessor :reference
|
6
|
+
validates :reference, :payment_reference => true
|
7
|
+
end
|
8
|
+
|
9
|
+
describe PaymentReferenceValidator do
|
10
|
+
subject {
|
11
|
+
PaymentReferenceTest.new
|
12
|
+
}
|
13
|
+
|
14
|
+
it "accepts 7 digit payment references" do
|
15
|
+
subject.reference = "1234567"
|
16
|
+
subject.should be_valid
|
17
|
+
end
|
18
|
+
|
19
|
+
it "accepts 9 digit payment references" do
|
20
|
+
subject.reference = "173456789"
|
21
|
+
subject.should be_valid
|
22
|
+
end
|
23
|
+
|
24
|
+
it "accepts 10 digit payment references" do
|
25
|
+
subject.reference = "5834567890"
|
26
|
+
subject.should be_valid
|
27
|
+
end
|
28
|
+
|
29
|
+
it "accepts 11 digit payment references" do
|
30
|
+
subject.reference = "79345678901"
|
31
|
+
subject.should be_valid
|
32
|
+
end
|
33
|
+
|
34
|
+
it "accepts 12 digit payment references" do
|
35
|
+
subject.reference = "603456789012"
|
36
|
+
subject.should be_valid
|
37
|
+
end
|
38
|
+
|
39
|
+
it "accepts 13 digit payment references" do
|
40
|
+
subject.reference = "2134567890123"
|
41
|
+
subject.should be_valid
|
42
|
+
end
|
43
|
+
|
44
|
+
it "accepts 14 digit payment references" do
|
45
|
+
subject.reference = "02345678901234"
|
46
|
+
subject.should be_valid
|
47
|
+
end
|
48
|
+
|
49
|
+
it "accepts 16 digit payment references" do
|
50
|
+
subject.reference = "5000056789012345"
|
51
|
+
subject.should be_valid
|
52
|
+
end
|
53
|
+
|
54
|
+
it "rejects on an 6 payment references" do
|
55
|
+
subject.reference = "123456"
|
56
|
+
subject.should_not be_valid
|
57
|
+
subject.errors[:reference].should be_present
|
58
|
+
end
|
59
|
+
|
60
|
+
it "rejects on an 8 payment references" do
|
61
|
+
subject.reference = "12345678"
|
62
|
+
subject.should_not be_valid
|
63
|
+
subject.errors[:reference].should be_present
|
64
|
+
end
|
65
|
+
|
66
|
+
it "rejects on an 15 payment references" do
|
67
|
+
subject.reference = "123456789012345"
|
68
|
+
subject.should_not be_valid
|
69
|
+
subject.errors[:reference].should be_present
|
70
|
+
end
|
71
|
+
|
72
|
+
it "rejects on obviously wrong numbers" do
|
73
|
+
subject.reference = "CHUCKNORRIS"
|
74
|
+
subject.should_not be_valid
|
75
|
+
subject.errors[:reference].should be_present
|
76
|
+
end
|
77
|
+
end
|
metadata
CHANGED
@@ -1,70 +1,82 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: elfproef
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Sytze Loor
|
9
13
|
- Ariejan de Vroom
|
10
14
|
autorequire:
|
11
15
|
bindir: bin
|
12
16
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
|
18
|
+
date: 2012-08-30 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
16
22
|
name: rake
|
17
|
-
requirement: &70232266117480 !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
|
-
requirements:
|
20
|
-
- - ! '>='
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '0'
|
23
|
-
type: :development
|
24
23
|
prerelease: false
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
34
31
|
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
35
|
prerelease: false
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: '0'
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 0
|
42
|
+
version: "0"
|
45
43
|
type: :development
|
44
|
+
version_requirements: *id002
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: guard-rspec
|
46
47
|
prerelease: false
|
47
|
-
|
48
|
-
|
48
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
type: :development
|
56
|
+
version_requirements: *id003
|
57
|
+
- !ruby/object:Gem::Dependency
|
49
58
|
name: activemodel
|
50
|
-
requirement: &70232266116040 !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
|
-
requirements:
|
53
|
-
- - ! '>='
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '0'
|
56
|
-
type: :runtime
|
57
59
|
prerelease: false
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id004
|
69
|
+
description: Validation for Dutch bank account numbers, Citizen Service Numbers (BSN) and Payment reference
|
70
|
+
email:
|
62
71
|
- sytze@tweedledum.nl
|
63
72
|
- ariejan@ariejan.net
|
64
73
|
executables: []
|
74
|
+
|
65
75
|
extensions: []
|
76
|
+
|
66
77
|
extra_rdoc_files: []
|
67
|
-
|
78
|
+
|
79
|
+
files:
|
68
80
|
- .gitignore
|
69
81
|
- .travis.yml
|
70
82
|
- Gemfile
|
@@ -75,35 +87,44 @@ files:
|
|
75
87
|
- lib/elfproef.rb
|
76
88
|
- lib/elfproef/bank_account_validator.rb
|
77
89
|
- lib/elfproef/bsn_validator.rb
|
90
|
+
- lib/elfproef/payment_reference_validator.rb
|
78
91
|
- lib/elfproef/version.rb
|
79
92
|
- spec/bank_account_validator_spec.rb
|
80
93
|
- spec/bsn_validator_spec.rb
|
94
|
+
- spec/payment_reference_validator_spec.rb
|
81
95
|
- spec/spec_helper.rb
|
96
|
+
has_rdoc: true
|
82
97
|
homepage: https://github.com/sytzeloor/elfproef
|
83
98
|
licenses: []
|
99
|
+
|
84
100
|
post_install_message:
|
85
101
|
rdoc_options: []
|
86
|
-
|
102
|
+
|
103
|
+
require_paths:
|
87
104
|
- lib
|
88
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
requirements:
|
97
|
-
- -
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
100
119
|
requirements: []
|
120
|
+
|
101
121
|
rubyforge_project: elfproef
|
102
|
-
rubygems_version: 1.
|
122
|
+
rubygems_version: 1.3.6
|
103
123
|
signing_key:
|
104
124
|
specification_version: 3
|
105
|
-
summary: Validation for Dutch bank account numbers
|
106
|
-
test_files:
|
125
|
+
summary: Validation for Dutch bank account numbers, Citizen Service Numbers (BSN) and Payment reference
|
126
|
+
test_files:
|
107
127
|
- spec/bank_account_validator_spec.rb
|
108
128
|
- spec/bsn_validator_spec.rb
|
129
|
+
- spec/payment_reference_validator_spec.rb
|
109
130
|
- spec/spec_helper.rb
|