ci_uy 0.1.3 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ci_uy +2 -0
- data/lib/ci_uy.rb +20 -14
- metadata +9 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dbba1cb5e88bdacc423cfcc8cd0b98d17630b1e54ee6882da82659900711add
|
4
|
+
data.tar.gz: 2120004058a999cd0278b561eff4cbacaeb6e17ee7c65070b70eabc47d8839b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8707b4f711062d3693bb54e90ad44ad3a62f70f62bef5010142f7af1c7a27b770502aab6caab58440ebf32d31727bf2dcb75e5bc318922bd7f090829050a1794
|
7
|
+
data.tar.gz: 3e4ecc39307fff5fcc31758909d52d91057a8eb3d506d7995c4b77fcb7ed3e28190c15387d8fe6bba69a131562c213c093745f2c5d5d1145053f4888cb82b439
|
data/bin/ci_uy
CHANGED
data/lib/ci_uy.rb
CHANGED
@@ -1,37 +1,43 @@
|
|
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`.
|
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
|
10
|
+
#
|
5
11
|
# rubocop:disable Naming/UncommunicativeMethodParamName
|
6
12
|
module CiUY
|
7
|
-
def self.validation_digit(
|
8
|
-
ci = transform(
|
9
|
-
|
10
|
-
a = 0
|
13
|
+
def self.validation_digit(input)
|
14
|
+
ci = transform(input)
|
15
|
+
a = []
|
11
16
|
(0..6).each do |i|
|
12
|
-
a
|
17
|
+
a << ('2987634'[i].to_i * ci[i].to_i)
|
13
18
|
end
|
14
|
-
(10 - (a % 10)).to_s[-1]
|
19
|
+
(10 - (a.inject(:+) % 10)).to_s[-1]
|
15
20
|
end
|
16
21
|
|
17
|
-
def self.validate_ci(
|
18
|
-
|
22
|
+
def self.validate_ci(input)
|
23
|
+
# Using to_a to keep 1.9.3 compatibility
|
24
|
+
ci = transform(input).chars.to_a
|
19
25
|
return false if ci.length < 6
|
20
|
-
|
26
|
+
|
27
|
+
digit = ci[-1]
|
21
28
|
ci = ci[0..-2]
|
22
|
-
get_validation_digit(ci) ==
|
29
|
+
get_validation_digit(ci.join) == digit
|
23
30
|
end
|
24
31
|
|
25
32
|
def self.random
|
26
33
|
ci = rand(1_000_000..9_999_999).to_s
|
27
|
-
ci
|
28
|
-
ci
|
34
|
+
ci + get_validation_digit(ci)
|
29
35
|
end
|
30
36
|
|
31
37
|
def self.transform(ci)
|
38
|
+
ci = '0' + ci if ci.size == 6
|
32
39
|
ci = ci.to_s if ci.is_a? Integer
|
33
|
-
ci.
|
34
|
-
ci
|
40
|
+
ci.chars.reject { |i| i.match(/\D/) }.join
|
35
41
|
end
|
36
42
|
|
37
43
|
class << self
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ci_uy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Briano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A gem to validate Uruguayan Identity Documents (Cedula de Identidad Uruguaya)
|
14
14
|
email: fernando@picandocodigo.net
|
@@ -22,14 +22,12 @@ files:
|
|
22
22
|
homepage: https://github.com/picandocodigo/ci_uy
|
23
23
|
licenses:
|
24
24
|
- LGPL-2.1
|
25
|
-
metadata:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
Atención: Desde la versión 0.1.3 los números con menos de 6 dígitos no son válidos.
|
32
|
-
|
25
|
+
metadata:
|
26
|
+
homepage_uri: https://github.com/picandocodigo/ci_uy/
|
27
|
+
changelog_uri: https://github.com/picandocodigo/ci_uy/blob/master/CHANGELOG
|
28
|
+
source_code_uri: https://github.com/picandocodigo/ci_uy/
|
29
|
+
bug_tracker_uri: https://github.com/picandocodigo/ci_uy/issues
|
30
|
+
post_install_message:
|
33
31
|
rdoc_options: []
|
34
32
|
require_paths:
|
35
33
|
- lib
|
@@ -44,8 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
42
|
- !ruby/object:Gem::Version
|
45
43
|
version: '0'
|
46
44
|
requirements: []
|
47
|
-
|
48
|
-
rubygems_version: 2.7.6
|
45
|
+
rubygems_version: 3.0.3
|
49
46
|
signing_key:
|
50
47
|
specification_version: 4
|
51
48
|
summary: CiUY Validate Uruguayan cedula numbers
|