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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ci_uy +2 -0
  3. data/lib/ci_uy.rb +20 -14
  4. metadata +9 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1388476217e551d47b5eb9c0d100790566d9e590646722705c7ec4990b1ee162
4
- data.tar.gz: 1c329eed7b4e4af2866d9f401b18a24826ba8072517fa26bf45411a145d08136
3
+ metadata.gz: 2dbba1cb5e88bdacc423cfcc8cd0b98d17630b1e54ee6882da82659900711add
4
+ data.tar.gz: 2120004058a999cd0278b561eff4cbacaeb6e17ee7c65070b70eabc47d8839b2
5
5
  SHA512:
6
- metadata.gz: 6baf373a37bf4643c679b3d7c516b06652b32db8c294b0cebcc629b34f8e9aacaea6c4d2c8fe6f101443a27bccf9aa8c9c875dd0a959f02c2a30fd715762988f
7
- data.tar.gz: f39c6b501a82d57b0d6796da1db2773521f71ff89cc2639da9f63edf1b4cf889bbd501f5af6ad5890edb0d817be3159b86eabbd87b1aa8c1494f84ec3e056ecd
6
+ metadata.gz: 8707b4f711062d3693bb54e90ad44ad3a62f70f62bef5010142f7af1c7a27b770502aab6caab58440ebf32d31727bf2dcb75e5bc318922bd7f090829050a1794
7
+ data.tar.gz: 3e4ecc39307fff5fcc31758909d52d91057a8eb3d506d7995c4b77fcb7ed3e28190c15387d8fe6bba69a131562c213c093745f2c5d5d1145053f4888cb82b439
data/bin/ci_uy CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'ci_uy'
3
5
 
4
6
  args = ARGV.dup
@@ -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(ci)
8
- ci = transform(ci)
9
- ci = '0' + ci if ci.size == 6
10
- a = 0
13
+ def self.validation_digit(input)
14
+ ci = transform(input)
15
+ a = []
11
16
  (0..6).each do |i|
12
- a += ('2987634'[i].to_i * ci[i].to_i)
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(ci)
18
- ci = transform(ci)
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
- dig = ci[-1]
26
+
27
+ digit = ci[-1]
21
28
  ci = ci[0..-2]
22
- get_validation_digit(ci) == dig
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 += get_validation_digit(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.gsub!(/\D/, '')
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.3
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: 2018-04-11 00:00:00.000000000 Z
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
- post_install_message: |2+
27
-
28
- Thanks for installing CiUY!
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
-
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
- rubyforge_project:
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