id_number_latam 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e80aa7c68a1f2484c6f35de0c9d02c13ffe69e6107197935fb1dd376d09a30d
4
- data.tar.gz: 946cbdfe49d99086b4b820965736b5718c3acb0b2068ee8b815ce35440d70fd7
3
+ metadata.gz: 2d576250026c5719d78d7f58e666f453cedb91f35e443d33d7c08a61e1459fb7
4
+ data.tar.gz: eb26e7e4bec596cf7959b3a95338f4bcf0c4af711e1b6457f809c3a29e7b1b68
5
5
  SHA512:
6
- metadata.gz: 83cd67a4b9d0b771c43870d4a6b8f57335f0a63d3208089dcd380618c831039b80bd8a23a62009230dff50c87afb5cba1f2fe6d88af8a54c411fb6cdb3ef9bc9
7
- data.tar.gz: '089045a94d85e69c34a535b38c8a865fb7340c30e01405b0e169be38a76dcd863d8f785f2d50d55e44be168a9af3247cba20e4d97db47dddd7755db0442c32bb'
6
+ metadata.gz: 40e6eef28dea09cefa2a037f87382cc359c5358e6856ec56389baf8e496b7c65bf885d330da420e61047b58c02e1607074d4c8cc1a4b6ecce5ac5d60a63f0a48
7
+ data.tar.gz: 13fff73a42a11dd5f1a9d46031c95fc45806247c31f225f4cbbec730e3b28db2e182f2b45ad1a5ff57e5b0202d31246951458b9ac22873ce458dfaee9c3c9da9
data/README.md CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  [![Ruby](https://github.com/ronzalo/id_number_latam/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/ronzalo/id_number_latam/actions/workflows/main.yml)
4
4
 
5
- A gem to validate the format of the identification number in some of latam countries, currently only for Chile, Ecuador and Uruguay, but it can be easily extended to other countries.
5
+ A gem to validate the format of the identification number in some of latam countries, currently only for Argentina, Chile, Ecuador, Paraguay, Perú and Uruguay, but it can be easily extended to other countries.
6
6
 
7
7
  ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'id_number_latam', github: 'ronzalo/id_number_latam'
12
+ gem 'id_number_latam'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -2,8 +2,11 @@
2
2
 
3
3
  require_relative "id_number_latam/version"
4
4
  require_relative "id_number_latam/base"
5
+ require_relative "id_number_latam/ar_dni"
5
6
  require_relative "id_number_latam/cl_dni"
6
7
  require_relative "id_number_latam/ec_dni"
8
+ require_relative "id_number_latam/pe_dni"
9
+ require_relative "id_number_latam/py_dni"
7
10
  require_relative "id_number_latam/uy_dni"
8
11
 
9
12
  module IdNumberLatam
@@ -0,0 +1,29 @@
1
+ module IdNumberLatam
2
+ class ArDni < Base
3
+ # This Class allows validating the Argentinean Number (DNI).
4
+ # This document does not have a verification digit.
5
+
6
+ def initialize(id_number, opts = {})
7
+ super
8
+ @country = :ar
9
+ end
10
+
11
+ def unformat
12
+ id_number.gsub(/\D/, "")
13
+ end
14
+
15
+ def format
16
+ dni = unformat
17
+ formatted_dni = dni.match(/(\d{2,3})(\d{3})(\d{3})/)[1..-1].join(".")
18
+ end
19
+
20
+ def valid?
21
+ valid_length
22
+ end
23
+
24
+ def valid_length
25
+ unformat.size == 8
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IdNumberLatam
4
+ class PeDni < Base
5
+ attr_reader :digit
6
+
7
+ NUMBERS = [6, 7, 8, 9, 0, 1, 1, 2, 3, 4, 5].freeze
8
+ LETTER = %w[K A B C D E F G H I J].freeze
9
+
10
+ def initialize(id_number, opts = {})
11
+ super
12
+ @country = :pe
13
+ @digit = unformat.slice(-1)
14
+ end
15
+
16
+ def unformat
17
+ id_number.gsub(/\D/, "")
18
+ end
19
+
20
+ def format
21
+ dni = unformat
22
+ digit = dni.slice!(-1)
23
+ formatted_dni = dni.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse
24
+ [formatted_dni, digit].join("-")
25
+ end
26
+
27
+ def valid?
28
+ return false unless valid_length
29
+
30
+ dni = unformat
31
+ digit = dni.slice!(-1)
32
+
33
+ key = (11 - (dni.chars.zip("32765432".chars).map { |p| p.map(&:to_i).inject(&:*) }.sum % 11))
34
+
35
+ NUMBERS[key].to_s == digit
36
+ end
37
+
38
+ def valid_length
39
+ unformat.size == 9
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IdNumberLatam
4
+ class PyDni < Base
5
+ attr_reader :digit
6
+
7
+ def initialize(id_number, opts = {})
8
+ super
9
+ @country = :py
10
+ @digit = unformat.slice(-1)
11
+ end
12
+
13
+ def unformat
14
+ id_number.gsub(/\D/, "")
15
+ end
16
+
17
+ def format
18
+ dni = unformat
19
+ digit = dni.slice!(-1)
20
+ formatted_dni = dni.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse
21
+ [formatted_dni, digit].join("-")
22
+ end
23
+
24
+ def valid?
25
+ return false unless valid_length
26
+
27
+ dni = unformat
28
+ digit = dni.slice!(-1)
29
+
30
+ (11 - (dni.chars.reverse.zip("2345678".chars).map { |p| p.map(&:to_i).inject(&:*) }.sum % 11)).to_s == digit
31
+ end
32
+
33
+ def valid_length
34
+ unformat.size == 8
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IdNumberLatam
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: id_number_latam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gonzalo Moreno
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-20 00:00:00.000000000 Z
11
+ date: 2021-07-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Supported Countries: Chile, Uruguay, Ecuador'
14
14
  email:
@@ -31,9 +31,12 @@ files:
31
31
  - bin/setup
32
32
  - id_number_latam.gemspec
33
33
  - lib/id_number_latam.rb
34
+ - lib/id_number_latam/ar_dni.rb
34
35
  - lib/id_number_latam/base.rb
35
36
  - lib/id_number_latam/cl_dni.rb
36
37
  - lib/id_number_latam/ec_dni.rb
38
+ - lib/id_number_latam/pe_dni.rb
39
+ - lib/id_number_latam/py_dni.rb
37
40
  - lib/id_number_latam/uy_dni.rb
38
41
  - lib/id_number_latam/version.rb
39
42
  homepage: https://gonzalomoreno.me/id_number_latam