elfproef 0.0.1
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.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/README.md +69 -0
- data/Rakefile +8 -0
- data/elfproef.gemspec +28 -0
- data/lib/elfproef.rb +30 -0
- data/lib/version.rb +3 -0
- data/spec/elfproef_spec.rb +71 -0
- data/spec/spec_helper.rb +19 -0
- metadata +101 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Elfproef
|
2
|
+
|
3
|
+
This gem adds a validation method for Dutch bank account numbers and
|
4
|
+
Citizen Service Numbers (BSN). These can be validated using the
|
5
|
+
so-called Elfproef.
|
6
|
+
|
7
|
+
Based on:
|
8
|
+
[Elfproef](https://github.com/tilsammans/elfproef/) by tilsammans
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Install as a gem
|
13
|
+
|
14
|
+
gem install elfproef
|
15
|
+
|
16
|
+
Or add it to your gemfile
|
17
|
+
|
18
|
+
gem 'elfproef'
|
19
|
+
|
20
|
+
and run
|
21
|
+
|
22
|
+
bundle install
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Simply add "validates_elfproef_of" to your model class.
|
27
|
+
|
28
|
+
class User < ActiveRecord::Base
|
29
|
+
validates :bank_account, elfproef: true
|
30
|
+
validates :bsn, elfproef: true
|
31
|
+
end
|
32
|
+
|
33
|
+
## Bugs / Feature Requests
|
34
|
+
|
35
|
+
Please post them to
|
36
|
+
[Github Issues](https://github.com/sytzeloor/elfproef/issues).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Feel free to help out. Fork the project, write your specs and code and
|
41
|
+
create a pull request.
|
42
|
+
|
43
|
+
## Contributors
|
44
|
+
|
45
|
+
* Sytze Loor <sytze@tweedledum.nl> - original author
|
46
|
+
* Ariejan de Vroom <ariejan@ariejan.net>
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
Copyright (c) 2012 Sytze Loor
|
51
|
+
|
52
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
53
|
+
a copy of this software and associated documentation files (the
|
54
|
+
"Software"), to deal in the Software without restriction, including
|
55
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
56
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
57
|
+
permit persons to whom the Software is furnished to do so, subject to
|
58
|
+
the following conditions:
|
59
|
+
|
60
|
+
The above copyright notice and this permission notice shall be
|
61
|
+
included in all copies or substantial portions of the Software.
|
62
|
+
|
63
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
64
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
65
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
66
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
67
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
68
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
69
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/elfproef.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "elfproef"
|
7
|
+
s.version = Elfproef::VERSION
|
8
|
+
s.authors = ["Sytze Loor"]
|
9
|
+
s.email = ["sytze@tweedledum.nl"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Validation for Dutch bank account numbers and Citizen Service Numbers (BSN)}
|
12
|
+
s.description = %q{Validation for Dutch bank account numbers and Citizen Service Numbers (BSN)}
|
13
|
+
|
14
|
+
s.rubyforge_project = "elfproef"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
s.add_development_dependency "guard-rspec"
|
25
|
+
|
26
|
+
s.add_dependency "activemodel"
|
27
|
+
|
28
|
+
end
|
data/lib/elfproef.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "active_model"
|
2
|
+
require "active_model/validations"
|
3
|
+
|
4
|
+
# define my validator
|
5
|
+
class ElfproefValidator < ActiveModel::EachValidator
|
6
|
+
# implement the method where the validation logic must reside
|
7
|
+
def validate_each(record, attribute, value)
|
8
|
+
record.errors.add(attribute, options[:message] || "is not valid") unless Elfproef.elfproef(value)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
# Elfproef.
|
14
|
+
module Elfproef
|
15
|
+
# Calculates the elfproef of a Dutch bank account number or Citizen Service Number (BSN).
|
16
|
+
# Return value should be 0 (proof succeeded). Any other value means faillure.
|
17
|
+
# Postbank bank accounts (7 digits) cannot be validated using the elfproef and
|
18
|
+
# will always return 0 (success).
|
19
|
+
# http://nl.wikipedia.org/wiki/Elfproef
|
20
|
+
def self.elfproef(number)
|
21
|
+
number, sum = number.to_s, 0
|
22
|
+
number.gsub!(/\D/, '') # strip out any non-digit character.
|
23
|
+
return true if number.length == 7 # always pass postbank accounts (7 digits)
|
24
|
+
return false unless number =~ /^\d{9}$/ # account should be exactly 9 digits
|
25
|
+
(1..9).each do |c|
|
26
|
+
sum += number[-c].chr.to_i * c
|
27
|
+
end
|
28
|
+
sum % 11 == 0
|
29
|
+
end
|
30
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Elfproef do
|
4
|
+
|
5
|
+
account_class = Class.new do
|
6
|
+
include ActiveModel::Validations
|
7
|
+
attr_accessor :account
|
8
|
+
validates :account, :elfproef => true
|
9
|
+
end
|
10
|
+
|
11
|
+
# Nine digets are not allowed
|
12
|
+
it "tests account format" do
|
13
|
+
Elfproef.elfproef(123456).should == false
|
14
|
+
Elfproef.elfproef(1234567890).should == false
|
15
|
+
Elfproef.elfproef('12345678a').should == false
|
16
|
+
end
|
17
|
+
|
18
|
+
# Invalid accounts will a value greather then 0
|
19
|
+
it "tests invalid accounts" do
|
20
|
+
Elfproef.elfproef(999999999).should == false
|
21
|
+
Elfproef.elfproef('99.99.99.999').should == false
|
22
|
+
Elfproef.elfproef('99 99 99 999').should == false
|
23
|
+
end
|
24
|
+
|
25
|
+
# Valid accounts will return 0
|
26
|
+
it "tests valid accounts" do
|
27
|
+
Elfproef.elfproef(123456789).should == true
|
28
|
+
Elfproef.elfproef('12.34.56.789').should == true
|
29
|
+
Elfproef.elfproef('12 34 56 789').should == true
|
30
|
+
Elfproef.elfproef(1234567).should == true
|
31
|
+
Elfproef.elfproef('1234567').should == true
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
shared_examples_for "elfproef validations" do
|
36
|
+
subject { account_class.new }
|
37
|
+
|
38
|
+
it "fails when empty" do
|
39
|
+
subject.should_not be_valid
|
40
|
+
subject.errors[:account].should == errors
|
41
|
+
end
|
42
|
+
|
43
|
+
it "fails with an obviously wrong number" do
|
44
|
+
subject.account = "666"
|
45
|
+
subject.should_not be_valid
|
46
|
+
subject.errors[:account].should == errors
|
47
|
+
end
|
48
|
+
|
49
|
+
it "passes with a ING number" do
|
50
|
+
subject.account = "1234567"
|
51
|
+
subject.should be_valid
|
52
|
+
end
|
53
|
+
|
54
|
+
it "passes with a valid bank number" do
|
55
|
+
subject.account = "123456789"
|
56
|
+
subject.should be_valid
|
57
|
+
end
|
58
|
+
|
59
|
+
it "fails with an wrong bank number" do
|
60
|
+
subject.account = "999999999"
|
61
|
+
subject.should_not be_valid
|
62
|
+
subject.errors[:account].should == errors
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "English validations" do
|
68
|
+
let!(:errors) { [ "is not valid"] }
|
69
|
+
it_should_behave_like "elfproef validations"
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rspec'
|
6
|
+
require 'elfproef'
|
7
|
+
|
8
|
+
Dir["#{File.expand_path('../support', __FILE__)}/*.rb"].each do |file|
|
9
|
+
require file unless file =~ /fakeweb\/.*\.rb/
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
|
14
|
+
config.before :each do
|
15
|
+
end
|
16
|
+
|
17
|
+
config.after :each do
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elfproef
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sytze Loor
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70344757390700 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70344757390700
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70344757390200 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70344757390200
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: guard-rspec
|
38
|
+
requirement: &70344757389760 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70344757389760
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: activemodel
|
49
|
+
requirement: &70344757389240 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70344757389240
|
58
|
+
description: Validation for Dutch bank account numbers and Citizen Service Numbers
|
59
|
+
(BSN)
|
60
|
+
email:
|
61
|
+
- sytze@tweedledum.nl
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- .gitignore
|
67
|
+
- Gemfile
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- elfproef.gemspec
|
71
|
+
- lib/elfproef.rb
|
72
|
+
- lib/version.rb
|
73
|
+
- spec/elfproef_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
homepage: ''
|
76
|
+
licenses: []
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project: elfproef
|
95
|
+
rubygems_version: 1.8.17
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Validation for Dutch bank account numbers and Citizen Service Numbers (BSN)
|
99
|
+
test_files:
|
100
|
+
- spec/elfproef_spec.rb
|
101
|
+
- spec/spec_helper.rb
|