ci_uy 0.0.3 → 0.0.4

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 +18 -5
  2. metadata +4 -4
data/lib/ci_uy.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  module CiUY
2
+
2
3
  def self.get_validation_digit(ci)
3
- ci.gsub!(/\D/, '')
4
- if ci.size == 6
5
- ci = '0'+ci
6
- end
4
+ ci = transform(ci)
5
+ ci = '0' + ci if ci.size == 6
7
6
  a = 0
8
7
  (0..6).each do |i|
9
8
  a += ("2987634"[i].chr.to_i * ci[i].chr.to_i)
@@ -12,7 +11,7 @@ module CiUY
12
11
  end
13
12
 
14
13
  def self.validate_ci(ci)
15
- ci.gsub!(/\D/, '')
14
+ ci = transform(ci)
16
15
  dig = ci[-1].chr
17
16
  ci = ci[0..-2]
18
17
  self.get_validation_digit(ci) == dig
@@ -23,4 +22,18 @@ module CiUY
23
22
  ci += get_validation_digit(ci)
24
23
  ci
25
24
  end
25
+
26
+ def self.transform(ci)
27
+ if ci.is_a? Integer
28
+ ci = ci.to_s
29
+ end
30
+ ci.gsub!(/\D/, '')
31
+ ci
32
+ end
33
+
34
+ class << self
35
+ alias_method :validation_digit, :get_validation_digit
36
+ alias_method :validate, :validate_ci
37
+ alias_method :random, :get_random_ci
38
+ end
26
39
  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.3
4
+ version: 0.0.4
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-23 00:00:00.000000000 Z
12
+ date: 2013-11-21 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
@@ -21,7 +21,7 @@ files:
21
21
  homepage: http://rubygems.org/gems/ci_uy
22
22
  licenses:
23
23
  - GPL-3
24
- post_install_message:
24
+ post_install_message: Thanks for installing CiUY!
25
25
  rdoc_options: []
26
26
  require_paths:
27
27
  - lib
@@ -39,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
39
  version: '0'
40
40
  requirements: []
41
41
  rubyforge_project:
42
- rubygems_version: 1.8.24
42
+ rubygems_version: 1.8.25
43
43
  signing_key:
44
44
  specification_version: 3
45
45
  summary: CiUY Validate Uruguayan cedula numbers