Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds get random ci method

  • Loading branch information...
commit f16e64be015d5d652cda50c6a30ad6c0e6e04be1 1 parent 5e34e35
@picandocodigo authored
View
14 README.md
@@ -11,10 +11,12 @@ Install:
Use:
``` ruby
fernando@hoth ~ $ irb
-1.9.3p194 :001 > require 'ci_uy'
- => true
-1.9.3p194 :002 > CiUY.validate_ci("1.111.111-1")
- => true
-1.9.3p194 :003 > CiUY.get_validation_digit("2222222")
- => "2"
+1.9.3-p286 :001 > require 'ci_uy'
+ => true
+1.9.3-p286 :002 > CiUY.validate_ci("1.111.111-1")
+ => true
+1.9.3-p286 :003 > CiUY.get_validation_digit("2222222")
+ => "2"
+1.9.3-p286 :004 > CiUY.get_random_ci
+ => "13082956"
```
View
BIN  ci_uy-0.0.1.gem
Binary file not shown
View
2  ci_uy.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'ci_uy'
- s.version = '0.0.1'
+ s.version = '0.0.2'
s.date = '2013-01-03'
s.summary = "CiUY Validate Uruguayan cedula numbers"
s.description = "A gem to validate Uruguayan Identity Documents (Cedula de Identidad Uruguaya)"
View
8 lib/ci_uy.rb
@@ -3,7 +3,7 @@ def self.get_validation_digit(ci)
ci.gsub!(/\D/, '')
a = 0
(0..6).each do |i|
- a = a + ("2987634"[i].to_i * ci[i].to_i)
+ a += ("2987634"[i].to_i * ci[i].to_i)
end
(10 - (a % 10)).to_s[-1]
end
@@ -13,4 +13,10 @@ def self.validate_ci(ci)
dig = ci[-1]
self.get_validation_digit(ci) == dig
end
+
+ def self.get_random_ci
+ ci = rand(1000000..9999999).to_s
+ ci += get_validation_digit(ci)
+ ci
+ end
end
View
5 test/ci_uy_test.rb
@@ -29,4 +29,9 @@
ci = "1.111.222.1"
assert !CiUY.validate_ci(ci)
end
+
+ it "should get a valid random ci number" do
+ ci = CiUY.get_random_ci
+ assert CiUY.validate_ci(ci)
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.