id-please 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88724539a2ea5198559a16e216aebb9c2c0b2e34
4
+ data.tar.gz: 51fba4e7928fd4f2eafa1ea42c2679ed43154d3a
5
+ SHA512:
6
+ metadata.gz: 51ffe69657b205ae17192e49aeb1ba5473d8648bf842488bcf9010b489fe97f663ea506d8017afd239dd45546e071688a8f957bff5ea4a573fb1e1640fe1fab3
7
+ data.tar.gz: f1ad4051dfa602ebea510b5e498aa9364e5bb6233e97ee5f525099c20f5df9c8c957be7f8051f861e661c0f51e0d8da309592e6812ffcf2854931c24ec097dc6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Crowtec
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.
@@ -0,0 +1 @@
1
+ # id-please
@@ -0,0 +1,2 @@
1
+ require 'id-please/version'
2
+ require 'id-please/validator'
@@ -0,0 +1,34 @@
1
+ module IdPlease
2
+ module ES
3
+ class Validator
4
+ DNI_alphabet = 'TRWAGMYFPDXBNJZSQVHLCKE'
5
+
6
+ REGEX = {
7
+ dni: /^(\d{8})([#{DNI_alphabet}])$/,
8
+ nie: /^([XYZ])(\d{7})([#{DNI_alphabet}])$/,
9
+ cif: /^([ABCDEFGHJKLMNPQRSUVW])(\d{7})(\d)$/
10
+ }
11
+
12
+ def check id
13
+ REGEX.each do |k, v|
14
+ return send("validate_#{k}", id.upcase) unless id.upcase.match(v).nil?
15
+ end
16
+
17
+ raise "Invalid ID"
18
+ end
19
+
20
+ def validate_dni id
21
+ DNI_alphabet[id[0..7].to_i % 23] == id[8]
22
+ end
23
+
24
+ def validate_nie id
25
+ validate_dni("#{'XYZ'.index(id[0])}#{id[1..8]}")
26
+ end
27
+
28
+ def validate_cif id #TODO
29
+ raise "TODO"
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ Dir[File.dirname(__FILE__) + '/countries/*.rb'].each {|file| require file }
2
+
3
+ module IdPlease
4
+ class Validator
5
+ def self.check id, country
6
+ Object.const_get("IdPlease::#{country.upcase}::Validator").new.check(id)
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module IdPlease
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: id-please
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - crowtec
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem for id and passport validation.
14
+ email: info@crowtec.eu
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - README.md
21
+ - lib/id-please.rb
22
+ - lib/id-please/countries/es.rb
23
+ - lib/id-please/validator.rb
24
+ - lib/id-please/version.rb
25
+ homepage: https://github.com/crowtec/id-please
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.6.11
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Provides a helper to check if a national id or a passport value is valid.
49
+ test_files: []