identificamex 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 08a56adc68bd04aa000dd2e2fc18761a15c9f8be
4
+ data.tar.gz: f3499a518b6d5740a7527add55f4f420a4bc3cb3
5
+ SHA512:
6
+ metadata.gz: 4d6c9f5a9ca1ede3dc897d9c3adb20b87503d0352405b85b90cef43586c2d3bf7a6f966a25dc9b060fc5cc1e141969500ccc784336fcd23610ce61707f1de0fc
7
+ data.tar.gz: 7aa92cd762566d4ff229f7a2e63f2c836cf96f583a99d48c32e72dea16a18a2b51627bbfa935779becc42a8aac50d984840cb142563975d5dc82c355c258079b
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .ruby-gemset
19
+ *swp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in identificamex.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Azarel Doroteo Pacheco
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Identificamex
2
+
3
+ Gema con validadores para los formatos de la Clave Única de Registro de Población (CURP) y el Registro Federal de Contribuyentes (RFC) utilizados en México.
4
+ Los validadores se integran con el mecanismo que implementa ActiveModel para el resto de validadores de Rails.
5
+
6
+ ## Instalación
7
+
8
+ Agrega esta línea al archivo Gemfile de tu aplicación
9
+
10
+ gem 'identificamex'
11
+
12
+ Y después ejecuta:
13
+
14
+ $ bundle
15
+
16
+ O instálala por ti mismo de esta manera:
17
+
18
+ $ gem install identificamex
19
+
20
+ ## Uso
21
+
22
+ Agrega las validaciones de formato a los campos correspondientes.
23
+
24
+
25
+ ```ruby
26
+ class Employee < ActiveRecor::Base
27
+ validates :curp, presence: true, curp_format: true
28
+ validates :rfc, rfc_format: true, allow_blank: true
29
+ end
30
+ ```
31
+
32
+ ## Contribución
33
+
34
+ 1. Haz un fork de este repositorio
35
+ 2. Crea tu rama (`git checkout -b my-new-feature`)
36
+ 3. Haz commit de tus cambios (`git commit -am 'Add some feature'`)
37
+ 4. Haz push a la rama (`git push origin my-new-feature`)
38
+ 5. Crea un nuevo Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'lib/identificamex'
7
+ t.test_files = FileList['test/identificamex/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'identificamex/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "identificamex"
8
+ spec.version = Identificamex::VERSION
9
+ spec.authors = ["Azarel Doroteo Pacheco"]
10
+ spec.email = ["azarel.doroteo@logicalbricks.com"]
11
+ spec.description = %q{Validadores para los formatos de CURP y RFC}
12
+ spec.summary = %q{Validadores sencillos para los formatos de la Clave Única de Registro de Población (CURP) y el Registro Federal de Contribuyentes (RFC) utilizados en México}
13
+ spec.homepage = "https://github.com/LogicalBricks/identificamex"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'activemodel'
25
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class CurpFormatValidator < ActiveModel::EachValidator
3
+ def validate_each(object, attribute, value)
4
+ unless value =~ /\A[A-Z][AEIOUX][A-Z]{2}[0-9]{2}[0-1][0-9][0-3][0-9][MH][A-Z][BCDFGHJKLMNÑPQRSTVWXYZ]{4}[0-9A-Z][0-9]\z/i
5
+ object.errors[attribute] << (options[:message] || "no es una CURP válida")
6
+ end
7
+ end
8
+ end
9
+
10
+
@@ -0,0 +1,8 @@
1
+ require 'active_model'
2
+ require_relative "identificamex/version"
3
+ require_relative "curp_format_validator"
4
+ require_relative "rfc_format_validator"
5
+
6
+ module Identificamex
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,3 @@
1
+ module Identificamex
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class RfcFormatValidator < ActiveModel::EachValidator
3
+ def validate_each(object, attribute, value)
4
+ unless value =~ /\A[A-ZÑ&]{3,4}[0-9]{2}[0-1][0-9][0-3][0-9]([A-Z0-9]{0,3})?\z/i
5
+ object.errors[attribute] << (options[:message] || "no es un RFC válido")
6
+ end
7
+ end
8
+ end
data/test/empleado.rb ADDED
@@ -0,0 +1,11 @@
1
+ class Empleado
2
+ include ActiveModel::Validations
3
+ attr_accessor :curp, :rfc
4
+ validates :curp, curp_format: true
5
+ validates :rfc, rfc_format: true
6
+
7
+ def initialize(options)
8
+ @curp = options[:curp] || 'AAAA111111HDFBBB01'
9
+ @rfc = options[:rfc] || 'AAAA111111AAA'
10
+ end
11
+ end
@@ -0,0 +1,60 @@
1
+ require_relative '../test_helper'
2
+ require_relative '../empleado'
3
+
4
+ describe 'curp validator' do
5
+
6
+ describe 'with valid data' do
7
+ it 'accepts curp (hombre)' do
8
+ Empleado.new(curp: 'AAAA111111HDFBBB01').must_be :valid?
9
+ end
10
+
11
+ it 'accepts curp (mujer)' do
12
+ Empleado.new(curp: 'AAAA111111MDFBBB01').must_be :valid?
13
+ end
14
+
15
+ it 'accepts curp (digito anti-duplicado alfanumérico)' do
16
+ Empleado.new(curp: 'AAAA111111HDFBBBA1').must_be :valid?
17
+ end
18
+ end # with valid data
19
+
20
+ describe 'with invalid data' do
21
+ it 'refuses curp (nombre con digito en lugar de letra)' do
22
+ Empleado.new(curp: '9AAA111111HDFBBB01').wont_be :valid?
23
+ end
24
+
25
+ it 'refuses curp (caracter invalido)' do
26
+ Empleado.new(curp: 'A*AA111111HDFBBB01').wont_be :valid?
27
+ end
28
+
29
+ it 'refuses curp (falta un digito en la fecha)' do
30
+ Empleado.new(curp: 'AAAA11111HDFBBB01').wont_be :valid?
31
+ end
32
+
33
+ it 'refuses curp (falta un caracter en los datos del nombre)' do
34
+ Empleado.new(curp: 'AAA111111HDFBBB01').wont_be :valid?
35
+ end
36
+
37
+ it 'refuses curp (el dia es invalido 42)' do
38
+ Empleado.new(curp: 'AAAA111142HDFBBB01').wont_be :valid?
39
+ end
40
+
41
+ it 'refuses curp (el mes es invaido 25)' do
42
+ Empleado.new(curp: 'AAAA112511HDFBBB01').wont_be :valid?
43
+ end
44
+
45
+ it 'refuses curp (sexo es inválido K)' do
46
+ Empleado.new(curp: 'AAAA111111KDFBBB01').wont_be :valid?
47
+ end
48
+
49
+ it 'refuses curp (caracteres de consonantes tiene alguna vocal)' do
50
+ Empleado.new(curp: 'AAAA111111HDFABB01').wont_be :valid?
51
+ Empleado.new(curp: 'AAAA111111HDFBAB01').wont_be :valid?
52
+ Empleado.new(curp: 'AAAA111111HDFBBA01').wont_be :valid?
53
+ end
54
+
55
+ it 'refuses curp (digito verificador alfanumérico)' do
56
+ Empleado.new(curp: 'AAAA111111HDFBBB0A').wont_be :valid?
57
+ end
58
+ end # with invalid data
59
+
60
+ end
@@ -0,0 +1,58 @@
1
+ require_relative '../test_helper'
2
+ require_relative '../empleado'
3
+
4
+ describe 'rfc validator' do
5
+
6
+ describe 'with valid data' do
7
+ it 'accepts rfc (compl.must_be)' do
8
+ Empleado.new(rfc: 'AEIO111111AEI').must_be :valid?
9
+ end
10
+
11
+ it 'accepts rfc (con 3 caracteres para el nombre)' do
12
+ Empleado.new(rfc: 'AEI111111AEI').must_be :valid?
13
+ end
14
+
15
+ it 'accepts rfc (sin homoclave)' do
16
+ Empleado.new(rfc: 'AEIO111111').must_be :valid?
17
+ end
18
+
19
+ it 'accepts rfc (sin homoclave y con 3 caracteres para el nombre)' do
20
+ Empleado.new(rfc: 'AEI111111').must_be :valid?
21
+ end
22
+
23
+ it 'accepts rfc (d.must_bes de nombre con Ñ)' do
24
+ Empleado.new(rfc: 'ÑAEI111111AEI').must_be :valid?
25
+ end
26
+
27
+ it 'accepts rfc (d.must_bes de nombre con &)' do
28
+ Empleado.new(rfc: 'A&O111111AEI').must_be :valid?
29
+ end
30
+ end # with valid data
31
+
32
+ describe 'with invalid data' do
33
+ it 'refuses rfc (nombre con dig.must_be en lugar de letra)' do
34
+ Empleado.new(rfc: '9AEI111111').wont_be :valid?
35
+ end
36
+
37
+ it 'refuses rfc (caracter invalido)' do
38
+ Empleado.new(rfc: 'A*OU111111').wont_be :valid?
39
+ end
40
+
41
+ it 'refuses rfc (falta un dig.must_be en la fecha)' do
42
+ Empleado.new(rfc: 'AEIO11111').wont_be :valid?
43
+ end
44
+
45
+ it 'refuses rfc (falta un caracter en los d.must_bes del nombre)' do
46
+ Empleado.new(rfc: 'AE111111').wont_be :valid?
47
+ end
48
+
49
+ it 'refuses rfc (el dia es invalido 42)' do
50
+ Empleado.new(rfc: 'AEIO111142').wont_be :valid?
51
+ end
52
+
53
+ it 'refuses rfc (el mes es invaido 25)' do
54
+ Empleado.new(rfc: 'AEIO112511').wont_be :valid?
55
+ end
56
+ end # with invalid data
57
+
58
+ end
@@ -0,0 +1,3 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require_relative '../lib/identificamex'
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: identificamex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Azarel Doroteo Pacheco
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activemodel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Validadores para los formatos de CURP y RFC
56
+ email:
57
+ - azarel.doroteo@logicalbricks.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .ruby-version
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - identificamex.gemspec
69
+ - lib/curp_format_validator.rb
70
+ - lib/identificamex.rb
71
+ - lib/identificamex/version.rb
72
+ - lib/rfc_format_validator.rb
73
+ - test/empleado.rb
74
+ - test/identificamex/curp_format_validator_test.rb
75
+ - test/identificamex/rfc_format_validator_test.rb
76
+ - test/test_helper.rb
77
+ homepage: https://github.com/LogicalBricks/identificamex
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.5
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Validadores sencillos para los formatos de la Clave Única de Registro de
101
+ Población (CURP) y el Registro Federal de Contribuyentes (RFC) utilizados en México
102
+ test_files:
103
+ - test/empleado.rb
104
+ - test/identificamex/curp_format_validator_test.rb
105
+ - test/identificamex/rfc_format_validator_test.rb
106
+ - test/test_helper.rb