ci_uy 0.1.3 → 1.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 +4 -4
- data/bin/ci_uy +5 -3
- data/lib/ci_uy.rb +30 -28
- metadata +67 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f8bd8a4ba177f5c66869e0202f615b8b122b2faa6801237518e3668b799096fc
|
|
4
|
+
data.tar.gz: f54475bce2be7bfe53a1c16f4b22a5bcc68c9f658ef6bbeef202b6eef11c98a3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f87ceef3f205c8bb9c6b9cac1584aa0c4d8a9c3534568e64effe902e2ec813c92515d8398b85dce4d2f87e579aec41c1d8a95db33071e4a1ea2c4d3655a92915
|
|
7
|
+
data.tar.gz: 3ec2395fd50c836a0f2397aea9af3f5768e01746c334575a32b1e9869cacf66e7ccf8f8d9babd449da0b060240fc0ec860e91847295b9479e19a749689976c87
|
data/bin/ci_uy
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
2
4
|
require 'ci_uy'
|
|
3
5
|
|
|
4
6
|
args = ARGV.dup
|
|
5
7
|
|
|
6
8
|
case args[0]
|
|
7
|
-
when
|
|
9
|
+
when 'validate' || 'validate_ci'
|
|
8
10
|
puts CiUY.validate args[1].dup
|
|
9
|
-
when
|
|
11
|
+
when 'random' || 'get_random_ci'
|
|
10
12
|
puts CiUY.random
|
|
11
|
-
when
|
|
13
|
+
when 'validation_digit' || 'get_validation_digit'
|
|
12
14
|
puts CiUY.validation_digit args[1].dup
|
|
13
15
|
else
|
|
14
16
|
puts <<-MANUAL
|
data/lib/ci_uy.rb
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# CiUY main validation. The gem receives a string and doesn't care what you use
|
|
2
4
|
# to separate the digits, it gets the numbers from the string and checks the
|
|
3
5
|
# verification digit. So all of these formats are valid: `1.111.111-1`,
|
|
4
6
|
# `1_111_111_1`, `1.111.111/1`.
|
|
5
|
-
#
|
|
7
|
+
# The validation algorithm is:
|
|
8
|
+
# Multiply each digit by 2, 9, 8, 7, 6, 3, 4 one to one
|
|
9
|
+
# Then do 10 - (sum mod 10), that's the verification digit
|
|
6
10
|
module CiUY
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
class << self
|
|
12
|
+
def validation_digit(input)
|
|
13
|
+
ci = transform(input)
|
|
14
|
+
a = []
|
|
15
|
+
7.times do |i|
|
|
16
|
+
a << ('2987634'[i].to_i * ci[i].to_i)
|
|
17
|
+
end
|
|
18
|
+
(10 - (a.inject(:+) % 10)).to_s[-1]
|
|
13
19
|
end
|
|
14
|
-
(10 - (a % 10)).to_s[-1]
|
|
15
|
-
end
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
ci = ci[0..-2]
|
|
22
|
-
get_validation_digit(ci) == dig
|
|
23
|
-
end
|
|
21
|
+
def validate_ci(input)
|
|
22
|
+
# Using to_a to keep 1.9.3 compatibility
|
|
23
|
+
ci = transform(input).chars.to_a
|
|
24
|
+
return false if ci.length < 6
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
ci
|
|
29
|
-
end
|
|
26
|
+
digit = ci.pop
|
|
27
|
+
get_validation_digit(ci.join) == digit
|
|
28
|
+
end
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
def random
|
|
31
|
+
ci = rand(1_000_000..9_999_999).to_s
|
|
32
|
+
ci + get_validation_digit(ci)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def transform(cedula)
|
|
36
|
+
cedula = "0#{cedula}" if cedula.size == 6
|
|
37
|
+
cedula = cedula.to_s if cedula.is_a? Integer
|
|
38
|
+
cedula.chars.reject { |i| i.match(/\D/) }.join
|
|
39
|
+
end
|
|
36
40
|
|
|
37
|
-
class << self
|
|
38
41
|
alias get_validation_digit validation_digit
|
|
39
42
|
alias validate validate_ci
|
|
40
43
|
alias get_random_ci random
|
|
41
44
|
end
|
|
42
45
|
end
|
|
43
|
-
# rubocop:enable Naming/UncommunicativeMethodParamName
|
metadata
CHANGED
|
@@ -1,15 +1,70 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ci_uy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Fernando Briano
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: debug
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: minitest
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rake
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: rubocop
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
13
68
|
description: A gem to validate Uruguayan Identity Documents (Cedula de Identidad Uruguaya)
|
|
14
69
|
email: fernando@picandocodigo.net
|
|
15
70
|
executables:
|
|
@@ -19,17 +74,13 @@ extra_rdoc_files: []
|
|
|
19
74
|
files:
|
|
20
75
|
- bin/ci_uy
|
|
21
76
|
- lib/ci_uy.rb
|
|
22
|
-
homepage: https://
|
|
77
|
+
homepage: https://codeberg.org/picandocodigo/ci_uy
|
|
23
78
|
licenses:
|
|
24
|
-
- LGPL-2.1
|
|
25
|
-
metadata:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Warning: Since version 0.1.3, numbers with less than 6 digits are not valid.
|
|
31
|
-
Atención: Desde la versión 0.1.3 los números con menos de 6 dígitos no son válidos.
|
|
32
|
-
|
|
79
|
+
- LGPL-2.1-or-later
|
|
80
|
+
metadata:
|
|
81
|
+
homepage_uri: https://codeberg.org/picandocodigo/ci_uy
|
|
82
|
+
changelog_uri: https://codeberg.org/picandocodigo/ci_uy/src/branch/main/CHANGELOG
|
|
83
|
+
bug_tracker_uri: https://codeberg.org/picandocodigo/ci_uy/issues
|
|
33
84
|
rdoc_options: []
|
|
34
85
|
require_paths:
|
|
35
86
|
- lib
|
|
@@ -37,16 +88,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
37
88
|
requirements:
|
|
38
89
|
- - ">="
|
|
39
90
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
91
|
+
version: '2.5'
|
|
41
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
93
|
requirements:
|
|
43
94
|
- - ">="
|
|
44
95
|
- !ruby/object:Gem::Version
|
|
45
96
|
version: '0'
|
|
46
97
|
requirements: []
|
|
47
|
-
|
|
48
|
-
rubygems_version: 2.7.6
|
|
49
|
-
signing_key:
|
|
98
|
+
rubygems_version: 4.0.3
|
|
50
99
|
specification_version: 4
|
|
51
100
|
summary: CiUY Validate Uruguayan cedula numbers
|
|
52
101
|
test_files: []
|