national-ids-validator 1.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.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.travis.yml +15 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +68 -0
- data/Rakefile +10 -0
- data/lib/national-ids-validator/rules.yml +13 -0
- data/lib/national-ids-validator/validator.rb +14 -0
- data/lib/national-ids-validator/version.rb +3 -0
- data/lib/national_ids_validator.rb +119 -0
- data/national-ids-validator.gemspec +28 -0
- data/spec/general_validator_spec.rb +55 -0
- data/spec/no_fodselsnummer_validator_spec.rb +78 -0
- data/spec/pl_pesel_validator_spec.rb +78 -0
- data/spec/spec_helper.rb +23 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b67f3052b301f723580ea827a1cef144591b909b
|
4
|
+
data.tar.gz: 534fc4bb2742cf40dcf3c45da504967ff70aad3e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3e9a7bcaae7795c8c56eaebb5537afd665e0aa05d81f0d3b0ff12eaa6224c803e48c020e4767f9cfa6b32db30bafb61742dc8544c5a48fea994fd7ec6916d80
|
7
|
+
data.tar.gz: 2eed0394ff295d1346a200ff9bc0437c0e0e0ce9438f9a4964a3d83abc23fd39ee45b930a4353b21e073b81c43312cfe33fde3ec7286fddcee952524e185a1fa
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Grzegorz Brzezinka
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
[](http://badge.fury.io/rb/national-ids-validator)
|
2
|
+
[](https://travis-ci.org/matfiz/national-ids-validator)
|
3
|
+
[](https://coveralls.io/r/matfiz/national-ids-validator)
|
4
|
+
|
5
|
+
National IDs Validator for Ruby on Rails (Active Model)
|
6
|
+
======================
|
7
|
+
|
8
|
+
It provides validators for national identification numbers. Currently the following countries are supported:
|
9
|
+
* Norway (NO) - Fødselsnummer
|
10
|
+
* Poland (PL) - PESEL
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
Add to your Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'national-ids-validator'
|
18
|
+
```
|
19
|
+
|
20
|
+
Run:
|
21
|
+
|
22
|
+
```
|
23
|
+
bundle install
|
24
|
+
```
|
25
|
+
|
26
|
+
Then add the following to your model:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
validates :personal_id_attribute, :national_id => {country: "PL"}
|
30
|
+
```
|
31
|
+
|
32
|
+
## Options
|
33
|
+
A custom error message can be provided:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
validates :personal_id_attribute, :national_id => {country: "PL", message: "is not valid personal number"}
|
37
|
+
```
|
38
|
+
|
39
|
+
If the nil value should be allowed, it need to be explicitely stated:
|
40
|
+
```ruby
|
41
|
+
validates :personal_id_attribute, :national_id => {country: "PL", allow_nil: true}
|
42
|
+
```
|
43
|
+
|
44
|
+
## Retrieving data out of the personal number
|
45
|
+
Often personal number contains useful data like birth date and/or gender. You may use the following commands to retrieve them:
|
46
|
+
|
47
|
+
* gender
|
48
|
+
```ruby
|
49
|
+
require 'national_ids_validator'
|
50
|
+
NationalIdsValidator.new("12030599592", "NO").gender %returns 0
|
51
|
+
```
|
52
|
+
It will return *0* for man, *1* for woman and *nil* for invalid number.
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
61
|
+
|
62
|
+
## Credit
|
63
|
+
|
64
|
+
Based on https://github.com/balexand/email_validator and https://github.com/max-power/iban.
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
MIT License. Copyright 2009-2014 Grzegorz Brzezinka. http://brzezinka.eu
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
# Default directory to look in is `/specs`
|
5
|
+
# Run with `rake spec`
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
|
+
task.rspec_opts = ['--color', '--format', 'nested']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :spec
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#http://en.wikipedia.org/wiki/National_identification_number
|
2
|
+
|
3
|
+
pl:
|
4
|
+
length: 11
|
5
|
+
regexp: '(?<year>\d{2})(?<month>\d{2})(?<day>\d{2})(?<individual>\d{4})(?<control>\d{1})'
|
6
|
+
weights: '1379137913'
|
7
|
+
|
8
|
+
|
9
|
+
'no':
|
10
|
+
length: 11
|
11
|
+
regexp: '(?<day>\d{2})(?<month>\d{2})(?<year>\d{2})(?<individual>\d{3})(?<control>\d{2})'
|
12
|
+
weights1: '376189452' #provides multiplying weights for the sum of digits to compute a first control digit
|
13
|
+
weights2: '5432765432' #provides multiplying weights for the sum of digits to compute a second control digit
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Based on work from https://github.com/balexand/email_validator
|
2
|
+
class NationalIdValidator < ActiveModel::EachValidator
|
3
|
+
@@default_options = {country: "PL"}
|
4
|
+
|
5
|
+
def self.default_options
|
6
|
+
@@default_options
|
7
|
+
end
|
8
|
+
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
options = @@default_options.merge(self.options)
|
11
|
+
# name_validation = options[:strict_mode] ? "-a-z0-9+._" : "^@\\s"
|
12
|
+
record.errors.add(attribute, options[:message] || :invalid) unless NationalIdsValidator.valid?(value,options[:country])
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require "national-ids-validator/version"
|
2
|
+
require "yaml"
|
3
|
+
require "national-ids-validator/validator" #if defined? ActiveModel
|
4
|
+
|
5
|
+
class NationalIdsValidator
|
6
|
+
|
7
|
+
SUPPORTED_COUNTRY_CODES = %w(PL NO)
|
8
|
+
|
9
|
+
def self.specifications
|
10
|
+
@@rules ||= YAML.load_file(File.expand_path("national-ids-validator/rules.yml", File.dirname(__FILE__)))
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(value,country_code)
|
14
|
+
@country_code = country_code.to_s.strip.gsub(/\s+/, '').upcase
|
15
|
+
@value = value.to_s.strip.gsub(/\s+/, '').upcase
|
16
|
+
unless self.class::SUPPORTED_COUNTRY_CODES.include?(@country_code)
|
17
|
+
raise RuntimeError.new("Unexpected country code '#{country_code}' that is not yet supported")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.valid?(value,code)
|
22
|
+
new(value,code).valid?
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid?
|
26
|
+
valid_length? && valid_check_digits?
|
27
|
+
end
|
28
|
+
|
29
|
+
def valid_length?
|
30
|
+
!!specification && specification['length'] == @value.length
|
31
|
+
end
|
32
|
+
|
33
|
+
def valid_check_digits?
|
34
|
+
status = false
|
35
|
+
v = self.number_data
|
36
|
+
# binding.pry
|
37
|
+
|
38
|
+
case @country_code
|
39
|
+
when "NO"
|
40
|
+
#http://no.wikipedia.org/wiki/F%C3%B8dselsnummer
|
41
|
+
#first control digit
|
42
|
+
weights1 = specification['weights1']
|
43
|
+
first_sum = 0
|
44
|
+
0.upto(@value.length - 3).each do |i|
|
45
|
+
first_sum += @value[i].to_i*weights1[i].to_i
|
46
|
+
end
|
47
|
+
first_digit = 11 - (first_sum % 11)
|
48
|
+
#second control digit
|
49
|
+
weights2 = specification['weights2']
|
50
|
+
second_sum = 0
|
51
|
+
0.upto(@value.length - 2).each do |i|
|
52
|
+
second_sum += @value[i].to_i*weights2[i].to_i
|
53
|
+
end
|
54
|
+
second_digit = 11 - (second_sum % 11)
|
55
|
+
#check digits
|
56
|
+
calculated = [first_digit, second_digit].map!{|k| k == 11 ? 0 : k}
|
57
|
+
control = [v["control"][0].to_i, v["control"][1].to_i]
|
58
|
+
if calculated[0] == control[0] && calculated[1] == control[1]
|
59
|
+
status = true
|
60
|
+
end
|
61
|
+
# binding.pry
|
62
|
+
when "PL"
|
63
|
+
weights = specification['weights']
|
64
|
+
sum = 0
|
65
|
+
0.upto(@value.length - 2).each do |i|
|
66
|
+
sum += @value[i].to_i*weights[i].to_i
|
67
|
+
end
|
68
|
+
first_digit = 10 - (sum % 10)
|
69
|
+
calculated = first_digit == 10 ? 0 : first_digit
|
70
|
+
control = v["control"][0].to_i
|
71
|
+
if calculated == control
|
72
|
+
status = true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
return status
|
77
|
+
end
|
78
|
+
|
79
|
+
def number_data
|
80
|
+
@number_data ||= Regexp.new("^#{specification['regexp']}$").match(@value) if specification
|
81
|
+
end
|
82
|
+
|
83
|
+
def gender #0 - man, 1 - woman
|
84
|
+
if self.valid?
|
85
|
+
case @country_code
|
86
|
+
when "NO"
|
87
|
+
number_data['individual'][2] % 2 == 0 ? 1 : 0
|
88
|
+
when "PL"
|
89
|
+
number_data['individual'][3] % 2 == 0 ? 1 : 0
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
def specification
|
101
|
+
@specification ||= self.class.specifications[@country_code.downcase]
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
# def method_missing(method_name, *args)
|
107
|
+
# respond_to?(method_name) ? number_data[method_name] : super
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# def respond_to_missing?(method_name, include_private=false)
|
111
|
+
# (number_data && number_data.names.include?(method_name.to_s)) || super
|
112
|
+
# end
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'national-ids-validator/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "national-ids-validator"
|
9
|
+
spec.version = NationalIDsValidator::VERSION
|
10
|
+
spec.authors = ["Grzegorz Brzezinka"]
|
11
|
+
spec.email = ["grzegorz@brzezinka.eu"]
|
12
|
+
spec.description = %q{It provides validators for national identification numbers}
|
13
|
+
spec.summary = %q{Validation and formatting of national identification numbers, such as PESEL (PL), Fødselsnummer (NO) etc.}
|
14
|
+
spec.homepage = "https://github.com/matfiz/national-ids-validator"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake", "~> 0"
|
24
|
+
spec.add_development_dependency 'rspec', "~> 3.0"
|
25
|
+
spec.add_development_dependency 'pry', "~> 0"
|
26
|
+
spec.add_development_dependency 'activemodel', "~> 3"
|
27
|
+
spec.add_development_dependency "coveralls", "~> 0"
|
28
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestPolish < TestModel
|
4
|
+
validates :personal_number, :national_id => {country: "PL"}
|
5
|
+
end
|
6
|
+
|
7
|
+
class TestPolishWithMessage < TestModel
|
8
|
+
validates :personal_number, :national_id => {country: "PL", message: "is not valid personal number"}
|
9
|
+
end
|
10
|
+
|
11
|
+
class TestPolishAllowsNil < TestModel
|
12
|
+
validates :personal_number, :national_id => {country: "PL", message: "is not valid personal number", allow_nil: true}
|
13
|
+
end
|
14
|
+
|
15
|
+
class TestPolishAllowsNilFalse < TestModel
|
16
|
+
validates :personal_number, :national_id => {country: "PL", message: "is not valid personal number", allow_nil: false}
|
17
|
+
end
|
18
|
+
|
19
|
+
describe NationalIdsValidator do
|
20
|
+
|
21
|
+
describe "error messages" do
|
22
|
+
context "when the message is not defined" do
|
23
|
+
subject { TestPolish.new :personal_number => '12345678901' }
|
24
|
+
before { subject.valid? }
|
25
|
+
|
26
|
+
it "should add the default message" do
|
27
|
+
expect(subject.errors[:personal_number]).to include "is invalid"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when the message is defined" do
|
32
|
+
subject { TestPolishWithMessage.new :personal_number => '12345678901' }
|
33
|
+
before { subject.valid? }
|
34
|
+
|
35
|
+
it "should add the customized message" do
|
36
|
+
expect(subject.errors[:personal_number]).to include "is not valid personal number"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "nil personal number" do
|
42
|
+
it "should not be valid when :allow_nil option is missing" do
|
43
|
+
expect(TestPolish.new(:personal_number => nil)).not_to be_valid
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be valid when :allow_nil options is set to true" do
|
47
|
+
expect(TestPolishAllowsNil.new(:personal_number => nil)).to be_valid
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should not be valid when :allow_nil option is set to false" do
|
51
|
+
expect(TestPolishAllowsNilFalse.new(:personal_number => nil)).not_to be_valid
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestNorwegian < TestModel
|
4
|
+
validates :personal_number, :national_id => {country: "NO"}
|
5
|
+
end
|
6
|
+
|
7
|
+
describe NationalIdsValidator do
|
8
|
+
|
9
|
+
describe "validation" do
|
10
|
+
context "given the valid NO personal numbers" do
|
11
|
+
[
|
12
|
+
"15051273920",
|
13
|
+
"12039449925",
|
14
|
+
"12039449097",
|
15
|
+
"03121298286",
|
16
|
+
" 03121298286 "
|
17
|
+
].each do |personal_number|
|
18
|
+
|
19
|
+
it "#{personal_number.inspect} should be valid" do
|
20
|
+
expect(TestNorwegian.new(:personal_number => personal_number, country: "NO")).to be_valid
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context "given the invalid NO personal numbers", focus: true do
|
28
|
+
[
|
29
|
+
"",
|
30
|
+
"123",
|
31
|
+
"86020219131",
|
32
|
+
"@bar.com",
|
33
|
+
"86020219131\n<script>alert('hello')</script>"
|
34
|
+
].each do |personal_number|
|
35
|
+
|
36
|
+
it "#{personal_number.inspect} should not be valid" do
|
37
|
+
expect(TestNorwegian.new(:personal_number => personal_number, country: "NO")).not_to be_valid
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "gender" do
|
45
|
+
it "should return nil when invalid number provided" do
|
46
|
+
expect(NationalIdsValidator.new("123", "NO").gender).to be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
context "given the NO personal numbers of man" do
|
50
|
+
[
|
51
|
+
"12030599916",
|
52
|
+
"12030599754",
|
53
|
+
"12030599592",
|
54
|
+
"12030599169",
|
55
|
+
"12030598537"
|
56
|
+
].each do |personal_number|
|
57
|
+
|
58
|
+
it "#{personal_number.inspect} gener should be 0 - man" do
|
59
|
+
expect(NationalIdsValidator.new(personal_number, "NO").gender).to equal(0)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "given the NO personal numbers of woman" do
|
65
|
+
[
|
66
|
+
"14030599218",
|
67
|
+
"14030597479",
|
68
|
+
"14030594836",
|
69
|
+
"14030593023",
|
70
|
+
"14030594674"
|
71
|
+
].each do |personal_number|
|
72
|
+
it "#{personal_number.inspect} gener should be 1 - woman" do
|
73
|
+
expect(NationalIdsValidator.new(personal_number, "NO").gender).to equal(0)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestPolish < TestModel
|
4
|
+
validates :personal_number, :national_id => {country: "PL"}
|
5
|
+
end
|
6
|
+
|
7
|
+
describe NationalIdsValidator do
|
8
|
+
|
9
|
+
describe "validation" do
|
10
|
+
context "given the valid PL personal numbers" do
|
11
|
+
[
|
12
|
+
"86020219132",
|
13
|
+
"86040807100",
|
14
|
+
"02242100603",
|
15
|
+
" 02242100603 "
|
16
|
+
].each do |personal_number|
|
17
|
+
|
18
|
+
it "#{personal_number.inspect} should be valid" do
|
19
|
+
expect(TestPolish.new(:personal_number => personal_number)).to be_valid
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
context "given the invalid PL personal numbers" do
|
27
|
+
[
|
28
|
+
"",
|
29
|
+
"123",
|
30
|
+
"86020219131",
|
31
|
+
"@bar.com",
|
32
|
+
"86020219131\n<script>alert('hello')</script>"
|
33
|
+
].each do |personal_number|
|
34
|
+
|
35
|
+
it "#{personal_number.inspect} should not be valid" do
|
36
|
+
expect(TestPolish.new(:personal_number => personal_number)).not_to be_valid
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "gender" do
|
44
|
+
it "should return nil when invalid number provided" do
|
45
|
+
expect(NationalIdsValidator.new("123", "PL").gender).to be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
context "given the PL PESEL of man" do
|
49
|
+
[
|
50
|
+
"78111914774",
|
51
|
+
"04301513670",
|
52
|
+
"20021804054",
|
53
|
+
"49121503797",
|
54
|
+
"76053019771"
|
55
|
+
].each do |personal_number|
|
56
|
+
|
57
|
+
it "#{personal_number.inspect} gender should be 0 - man" do
|
58
|
+
expect(NationalIdsValidator.new(personal_number, "PL").gender).to equal(0)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "given the PL PESEL of woman" do
|
64
|
+
[
|
65
|
+
"67070203144",
|
66
|
+
"21121317741",
|
67
|
+
"21022314928",
|
68
|
+
"22050917321",
|
69
|
+
"30122117724"
|
70
|
+
].each do |personal_number|
|
71
|
+
it "#{personal_number.inspect} gender should be 1 - woman" do
|
72
|
+
expect(NationalIdsValidator.new(personal_number, "PL").gender).to equal(0)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec'
|
3
|
+
require 'active_model'
|
4
|
+
require 'pry'
|
5
|
+
require 'coveralls'
|
6
|
+
Coveralls.wear!
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
|
+
|
11
|
+
require 'national_ids_validator'
|
12
|
+
|
13
|
+
class TestModel
|
14
|
+
include ActiveModel::Validations
|
15
|
+
|
16
|
+
def initialize(attributes = {})
|
17
|
+
@attributes = attributes
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_attribute_for_validation(key)
|
21
|
+
@attributes[key]
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: national-ids-validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Grzegorz Brzezinka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
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'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activemodel
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: It provides validators for national identification numbers
|
98
|
+
email:
|
99
|
+
- grzegorz@brzezinka.eu
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".coveralls.yml"
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- lib/national-ids-validator/rules.yml
|
113
|
+
- lib/national-ids-validator/validator.rb
|
114
|
+
- lib/national-ids-validator/version.rb
|
115
|
+
- lib/national_ids_validator.rb
|
116
|
+
- national-ids-validator.gemspec
|
117
|
+
- spec/general_validator_spec.rb
|
118
|
+
- spec/no_fodselsnummer_validator_spec.rb
|
119
|
+
- spec/pl_pesel_validator_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
homepage: https://github.com/matfiz/national-ids-validator
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.2.2
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Validation and formatting of national identification numbers, such as PESEL
|
145
|
+
(PL), Fødselsnummer (NO) etc.
|
146
|
+
test_files:
|
147
|
+
- spec/general_validator_spec.rb
|
148
|
+
- spec/no_fodselsnummer_validator_spec.rb
|
149
|
+
- spec/pl_pesel_validator_spec.rb
|
150
|
+
- spec/spec_helper.rb
|