ci_uy 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/ci_uy.rb +13 -3
  2. metadata +2 -2
data/lib/ci_uy.rb CHANGED
@@ -1,16 +1,26 @@
1
1
  module CiUY
2
2
  def self.get_validation_digit(ci)
3
3
  ci.gsub!(/\D/, '')
4
+ if ci.size == 6
5
+ ci = '0'+ci
6
+ end
4
7
  a = 0
5
8
  (0..6).each do |i|
6
- a = a + ("2987634"[i].to_i * ci[i].to_i)
9
+ a += ("2987634"[i].chr.to_i * ci[i].chr.to_i)
7
10
  end
8
- (10 - (a % 10)).to_s[-1]
11
+ (10 - (a % 10)).to_s[-1].chr
9
12
  end
10
13
 
11
14
  def self.validate_ci(ci)
12
15
  ci.gsub!(/\D/, '')
13
- dig = ci[-1]
16
+ dig = ci[-1].chr
17
+ ci = ci[0..-2]
14
18
  self.get_validation_digit(ci) == dig
15
19
  end
20
+
21
+ def self.get_random_ci
22
+ ci = rand(1000000..9999999).to_s
23
+ ci += get_validation_digit(ci)
24
+ ci
25
+ end
16
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ci_uy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-03 00:00:00.000000000 Z
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A gem to validate Uruguayan Identity Documents (Cedula de Identidad Uruguaya)
15
15
  email: fernando@picandocodigo.net