ci_uy 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ci_uy +15 -6
- data/lib/ci_uy.rb +6 -6
- metadata +2 -2
data/bin/ci_uy
CHANGED
@@ -1,17 +1,26 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# -*- coding: utf-8 -*-
|
3
3
|
require 'ci_uy'
|
4
4
|
|
5
5
|
args = ARGV.dup
|
6
6
|
|
7
7
|
case args[0]
|
8
|
-
when (
|
8
|
+
when ('validate' || 'validate_ci')
|
9
9
|
puts CiUY.validate args[1].dup
|
10
|
-
when (
|
10
|
+
when ('random' || 'get_random_ci')
|
11
11
|
puts CiUY.random
|
12
|
-
when (
|
12
|
+
when ('validation_digit' || 'get_validation_digit')
|
13
13
|
puts CiUY.validation_digit args[1].dup
|
14
14
|
else
|
15
|
-
puts
|
15
|
+
puts <<EOS
|
16
|
+
|
17
|
+
Usage:
|
18
|
+
ci_uy [parameter[ci number]]
|
19
|
+
|
20
|
+
Possible parameters are:
|
21
|
+
validate [number] - validates given CI number, returns true or false
|
22
|
+
validation_digit [number] - returns validation digit for given number CI number
|
23
|
+
random - returns a random valid CI number.
|
24
|
+
|
25
|
+
EOS
|
16
26
|
end
|
17
|
-
CiUY.validate("36089925")
|
data/lib/ci_uy.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
1
3
|
module CiUY
|
2
4
|
def self.get_validation_digit(ci)
|
3
5
|
ci = transform(ci)
|
4
6
|
ci = '0' + ci if ci.size == 6
|
5
7
|
a = 0
|
6
8
|
(0..6).each do |i|
|
7
|
-
a += (
|
9
|
+
a += ('2987634'[i].to_i * ci[i].to_i)
|
8
10
|
end
|
9
11
|
(10 - (a % 10)).to_s[-1]
|
10
12
|
end
|
@@ -13,19 +15,17 @@ module CiUY
|
|
13
15
|
ci = transform(ci)
|
14
16
|
dig = ci[-1]
|
15
17
|
ci = ci[0..-2]
|
16
|
-
|
18
|
+
get_validation_digit(ci) == dig
|
17
19
|
end
|
18
20
|
|
19
21
|
def self.get_random_ci
|
20
|
-
ci = rand(
|
22
|
+
ci = rand(1_000_000..9_999_999).to_s
|
21
23
|
ci += get_validation_digit(ci)
|
22
24
|
ci
|
23
25
|
end
|
24
26
|
|
25
27
|
def self.transform(ci)
|
26
|
-
if ci.is_a? Integer
|
27
|
-
ci = ci.to_s
|
28
|
-
end
|
28
|
+
ci = ci.to_s if ci.is_a? Integer
|
29
29
|
ci.gsub!(/\D/, '')
|
30
30
|
ci
|
31
31
|
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.1.
|
4
|
+
version: 0.1.1
|
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: 2014-04-
|
12
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|