spain_dni 0.1.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/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/spain_dni.rb +55 -0
- data/lib/spain_dni/version.rb +3 -0
- data/spain_dni.gemspec +27 -0
- metadata +100 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 061f9f2f95eb968c32e23efad2fed26761d3a061cfe89dad57364639f8b4462d
|
|
4
|
+
data.tar.gz: 2fa77427829f29dad14d9ae58e79a655784bc8d2f9dd8a76ff8fa1b5973a2ad7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ab4204fa9b890e200a81d6a5630f94d4f0b3b52459be83c646f9f50bd2e642e513d1fdee16d5870d991a6adb2247e21b117444a3e98f9982663b3582848384dd
|
|
7
|
+
data.tar.gz: d5c0715922ccc88fc5c250cb32372a784b80492487b7cf6390a5765895c7240463b1028cfef4386a7e11140b1bf7dbf9537d989aa817e87baee3e16e3800509e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
spain_dni (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
diff-lcs (1.3)
|
|
10
|
+
rake (10.5.0)
|
|
11
|
+
rspec (3.7.0)
|
|
12
|
+
rspec-core (~> 3.7.0)
|
|
13
|
+
rspec-expectations (~> 3.7.0)
|
|
14
|
+
rspec-mocks (~> 3.7.0)
|
|
15
|
+
rspec-core (3.7.1)
|
|
16
|
+
rspec-support (~> 3.7.0)
|
|
17
|
+
rspec-expectations (3.7.0)
|
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
19
|
+
rspec-support (~> 3.7.0)
|
|
20
|
+
rspec-mocks (3.7.0)
|
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
|
+
rspec-support (~> 3.7.0)
|
|
23
|
+
rspec-support (3.7.1)
|
|
24
|
+
|
|
25
|
+
PLATFORMS
|
|
26
|
+
ruby
|
|
27
|
+
|
|
28
|
+
DEPENDENCIES
|
|
29
|
+
bundler (~> 1.16)
|
|
30
|
+
rake (~> 10.0)
|
|
31
|
+
rspec (~> 3.0)
|
|
32
|
+
spain_dni!
|
|
33
|
+
|
|
34
|
+
BUNDLED WITH
|
|
35
|
+
1.16.2
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 nevadajames
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# SpainDni
|
|
2
|
+
|
|
3
|
+
A tool for validating Spanish DNI/NIE numbers. Checks for validity, can calculate the check letter
|
|
4
|
+
and return type of id (DNI or NIE).
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Add this line to your application's Gemfile:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'spain_dni'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
$ bundle
|
|
17
|
+
|
|
18
|
+
Or install it yourself as:
|
|
19
|
+
|
|
20
|
+
$ gem install spain_dni
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
Create a new instance of Dni class:
|
|
25
|
+
```ruby
|
|
26
|
+
dni = SpainDni::Dni.new('53428132Y')
|
|
27
|
+
|
|
28
|
+
dni.valid?
|
|
29
|
+
=> true
|
|
30
|
+
|
|
31
|
+
dni.valid_letter
|
|
32
|
+
=> 'Y'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Id type can be checked by using:
|
|
36
|
+
```ruby
|
|
37
|
+
dni.id_type
|
|
38
|
+
=> 'DNI'
|
|
39
|
+
```
|
|
40
|
+
Or using the helper methods:
|
|
41
|
+
```
|
|
42
|
+
dni.dni?
|
|
43
|
+
=>true
|
|
44
|
+
|
|
45
|
+
dni.nie?
|
|
46
|
+
=> false
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Development
|
|
53
|
+
|
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "spain_dni"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/spain_dni.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require "spain_dni/version"
|
|
2
|
+
|
|
3
|
+
# Validates check letter for Spanish DNI and NIE
|
|
4
|
+
module SpainDni
|
|
5
|
+
class Dni
|
|
6
|
+
attr_accessor :id_number
|
|
7
|
+
|
|
8
|
+
def initialize(id_number)
|
|
9
|
+
@id_number = id_number.to_s
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def dni?
|
|
13
|
+
!@id_number[0].match(/\d/).nil?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def nie?
|
|
17
|
+
@id_number[0].match(/\d/).nil?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def check_letter
|
|
21
|
+
@id_number[-1]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def calculate_check
|
|
25
|
+
nie_letters = { X: 0, Y: 1, Z: 2 }
|
|
26
|
+
number = if nie?
|
|
27
|
+
[nie_letters[@id_number[0].to_sym], @id_number[1..-2]].join
|
|
28
|
+
else
|
|
29
|
+
@id_number.chop
|
|
30
|
+
end
|
|
31
|
+
number.to_i % 23
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def valid_letter
|
|
35
|
+
verifiers = {
|
|
36
|
+
0 => 'T', 1 => 'R', 2 => 'W', 3 => 'A', 4 => 'G', 5 => 'M',
|
|
37
|
+
6 => 'Y', 7 => 'F', 8 => 'P', 9 => 'D', 10 => 'X', 11 => 'B',
|
|
38
|
+
12 => 'N', 13 => 'J', 14 => 'Z' ,15 => 'S', 16 => 'Q',
|
|
39
|
+
17 => 'V', 18 => 'H', 19 => 'L', 20 => 'C', 21 => 'K', 22 => 'E'
|
|
40
|
+
}
|
|
41
|
+
verifiers.each do |key, value|
|
|
42
|
+
return value if calculate_check.to_i == key
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def valid?
|
|
47
|
+
check_letter == valid_letter
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def id_type
|
|
51
|
+
return nil unless valid?
|
|
52
|
+
nie? ? 'NIE' : 'DNI'
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/spain_dni.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "spain_dni/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "spain_dni"
|
|
8
|
+
spec.version = SpainDni::VERSION
|
|
9
|
+
spec.authors = ["nevadajames"]
|
|
10
|
+
spec.email = ["nevadajames@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{A gem to validate Spanish DNI/NIE numbers and generate fake ones}
|
|
13
|
+
spec.description = %q{This gem verifies the last letter or a DNI/NIE and has methods to generate fake ones for testing.}
|
|
14
|
+
spec.homepage = "https://github.com/nevadajames/spain_dni"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
spec.bindir = "exe"
|
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: spain_dni
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- nevadajames
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-07-12 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.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.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
|
+
description: This gem verifies the last letter or a DNI/NIE and has methods to generate
|
|
56
|
+
fake ones for testing.
|
|
57
|
+
email:
|
|
58
|
+
- nevadajames@gmail.com
|
|
59
|
+
executables: []
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files: []
|
|
62
|
+
files:
|
|
63
|
+
- ".gitignore"
|
|
64
|
+
- ".rspec"
|
|
65
|
+
- ".travis.yml"
|
|
66
|
+
- Gemfile
|
|
67
|
+
- Gemfile.lock
|
|
68
|
+
- LICENSE.txt
|
|
69
|
+
- README.md
|
|
70
|
+
- Rakefile
|
|
71
|
+
- bin/console
|
|
72
|
+
- bin/setup
|
|
73
|
+
- lib/spain_dni.rb
|
|
74
|
+
- lib/spain_dni/version.rb
|
|
75
|
+
- spain_dni.gemspec
|
|
76
|
+
homepage: https://github.com/nevadajames/spain_dni
|
|
77
|
+
licenses:
|
|
78
|
+
- MIT
|
|
79
|
+
metadata: {}
|
|
80
|
+
post_install_message:
|
|
81
|
+
rdoc_options: []
|
|
82
|
+
require_paths:
|
|
83
|
+
- lib
|
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
|
+
requirements:
|
|
91
|
+
- - ">="
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
requirements: []
|
|
95
|
+
rubyforge_project:
|
|
96
|
+
rubygems_version: 2.7.3
|
|
97
|
+
signing_key:
|
|
98
|
+
specification_version: 4
|
|
99
|
+
summary: A gem to validate Spanish DNI/NIE numbers and generate fake ones
|
|
100
|
+
test_files: []
|