ivanvr-faker_es_mx 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,4 @@
1
+ This work is licensed under the Creative Commons Attribution-Share Alike 2.5 Mexico License.
2
+
3
+ To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.5/mx/
4
+ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
data/README ADDED
@@ -0,0 +1,17 @@
1
+ I was using the Faker gem (http://faker.rubyforge.org/) to generate test data
2
+ for an application, but since the application is in spanish, the test data
3
+ looked weird.
4
+
5
+ So I created this small extension to address that.
6
+
7
+ Many of Faker's method have their mx_ prefixed counterpart in this extension.
8
+
9
+ I hope you find this as useful as I have.
10
+
11
+ To use:
12
+
13
+ gem install faker
14
+ gem install ivanvr-faker_es_mx --source=http://gems.github.com
15
+
16
+ require 'faker'
17
+ require 'faker_es_mx'
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'rake/testtask'
7
+
8
+ Dir['tasks/*.rake'].each {|t| load t }
9
+
10
+ spec = Gem::Specification.new do |s|
11
+ s.name = 'faker_es_mx'
12
+ s.version = '0.1.0'
13
+ s.has_rdoc = true
14
+ s.extra_rdoc_files = ['README', 'LICENSE']
15
+ s.summary = 'Faker extension for es_MX fakings!'
16
+ s.description = s.summary
17
+ s.author = 'Ivan Vega'
18
+ s.email = ''
19
+ # s.executables = ['your_executable_here']
20
+ s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
21
+ s.require_path = "lib"
22
+ s.bindir = "bin"
23
+ end
24
+
25
+ Rake::GemPackageTask.new(spec) do |p|
26
+ p.gem_spec = spec
27
+ p.need_tar = true
28
+ p.need_zip = true
29
+ end
30
+
31
+ Rake::RDocTask.new do |rdoc|
32
+ files =['README', 'LICENSE', 'lib/**/*.rb']
33
+ rdoc.rdoc_files.add(files)
34
+ rdoc.main = "README" # page to start on
35
+ rdoc.title = "faker_es_mx Docs"
36
+ rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
37
+ rdoc.options << '--line-numbers'
38
+ end
39
+
40
+ Rake::TestTask.new do |t|
41
+ t.test_files = FileList['test/**/*.rb']
42
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,71 @@
1
+ module Faker
2
+ class Address
3
+ MX_STATES = {
4
+ :AGU => { :abbr => 'Ags', :post_codes => 20..20, :name => 'Aguascalientes' },
5
+ :BCN => { :abbr => 'BC', :post_codes => 21..22, :name => 'Baja California' },
6
+ :BCS => { :abbr => 'BCS', :post_codes => 23..23, :name => 'Baja California Sur' },
7
+ :CAM => { :abbr => 'Camp', :post_codes => 24..24, :name => 'Campeche' },
8
+ :CHP => { :abbr => 'Coah', :post_codes => 25..27, :name => 'Coahuila' },
9
+ :CHH => { :abbr => 'Col', :post_codes => 28..28, :name => 'Colima' },
10
+ :COA => { :abbr => 'Chis', :post_codes => 29..30, :name => 'Chiapas' },
11
+ :COL => { :abbr => 'Chih', :post_codes => 31..33, :name => 'Chihuahua' },
12
+ :DIF => { :abbr => 'DF', :post_codes => 00..16, :name => 'Distrito Federal' },
13
+ :DUR => { :abbr => 'Dgo', :post_codes => 34..35, :name => 'Durango' },
14
+ :GUA => { :abbr => 'Gto', :post_codes => 36..38, :name => 'Guanajuato' },
15
+ :GRO => { :abbr => 'Gro', :post_codes => 39..41, :name => 'Guerrero' },
16
+ :HID => { :abbr => 'Hgo', :post_codes => 42..43, :name => 'Hidalgo' },
17
+ :JAL => { :abbr => 'Jal', :post_codes => 44..48, :name => 'Jalisco' },
18
+ :MEX => { :abbr => 'Mex', :post_codes => 50..57, :name => 'Estado de México' },
19
+ :MIC => { :abbr => 'Mich', :post_codes => 58..61, :name => 'Michoacán' },
20
+ :MOR => { :abbr => 'Mor', :post_codes => 62..62, :name => 'Morelos' },
21
+ :NAY => { :abbr => 'Nay', :post_codes => 63..63, :name => 'Nayarit' },
22
+ :NLE => { :abbr => 'NL', :post_codes => 64..67, :name => 'Nuevo León' },
23
+ :OAX => { :abbr => 'Oax', :post_codes => 68..71, :name => 'Oaxaca' },
24
+ :PUE => { :abbr => 'Pue', :post_codes => 72..75, :name => 'Puebla' },
25
+ :QUE => { :abbr => 'Qro', :post_codes => 76..76, :name => 'Querétaro' },
26
+ :ROO => { :abbr => 'QRoo', :post_codes => 77..77, :name => 'Quintana Roo' },
27
+ :SLP => { :abbr => 'SLP', :post_codes => 78..79, :name => 'San Luis Potosí' },
28
+ :SIN => { :abbr => 'Sin', :post_codes => 80..82, :name => 'Sinaloa' },
29
+ :SON => { :abbr => 'Son', :post_codes => 83..85, :name => 'Sonora' },
30
+ :TAB => { :abbr => 'Tab', :post_codes => 86..86, :name => 'Tabasco' },
31
+ :TAM => { :abbr => 'Tamps', :post_codes => 87..89, :name => 'Tamaulipas' },
32
+ :TLA => { :abbr => 'Tlax', :post_codes => 90..90, :name => 'Tlaxcala' },
33
+ :VER => { :abbr => 'Ver', :post_codes => 91..96, :name => 'Veracruz' },
34
+ :YUC => { :abbr => 'Yuc', :post_codes => 97..97, :name => 'Yucatán' },
35
+ :ZAC => { :abbr => 'Zac', :post_codes => 98..99, :name => 'Zacatecas'}
36
+ }
37
+
38
+ @mx_states_iso = MX_STATES.keys
39
+
40
+ class << self
41
+ # Returns a state in Mexico.
42
+ # Optionally ask for a specific state by its ISO code.
43
+ def mx_state(iso = nil)
44
+ iso ||= @mx_states_iso.rand
45
+ MX_STATES[iso][:name]
46
+ end
47
+
48
+ # Returns the abbreviation of a state according to INEGI.
49
+ # Optionally ask for a specific state by its ISO code.
50
+ def mx_state_abbr(iso = nil)
51
+ iso ||= @mx_states_iso.rand
52
+ MX_STATES[iso][:abbr]
53
+ end
54
+
55
+ # Returns the abbreviation of a state by its ISO code.
56
+ def mx_state_abbr_iso
57
+ @mx_states_iso.rand.to_s
58
+ end
59
+
60
+ # Returns a five digit postal code.
61
+ # Use the iso parameter to generate a valid
62
+ # post code for the specified ISO state.
63
+ # mx_postcode(mx_state_abbr_iso)
64
+ def mx_postcode(iso = nil)
65
+ iso ||= @mx_states_iso.rand
66
+ code = MX_STATES[iso][:post_codes].to_a.rand
67
+ "%05d" % (code * 1000 + rand(1000))
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,81 @@
1
+ module Faker
2
+ class Name
3
+ MX_NAMES = {
4
+ :female => %w(
5
+ Maria Guadalupe Carmen Rosa Claudia Fernanda Sofia Ana Karla Laura
6
+ Martha Alejandra Andrea Silvia Patricia Veronica Monica Margarita
7
+ Gabriela Isabel Alicia Gloria Elena Rosario Mariana Yolanda Julia
8
+ Cecilia Angelica Carolina
9
+ ),
10
+ :male => %w(
11
+ Juan Jose Carlos Luis Jesus Manuel Antonio Alberto Francisco Alejandro
12
+ Fernando Roberto Jorge Eduardo Mario Marco Miguel Victor Rogelio Daniel
13
+ Sergio Arturo Alfredo Martin Armando Eduardo Enrique Hector
14
+ )
15
+ }
16
+
17
+ MX_LAST_NAMES = %w(
18
+ Hernandez Garcia Martinez Lopez Gonzalez Gomez Rodriguez Perez Sanchez
19
+ Rivera Ramirez Flores Villegas Guerrero Monroy Naranjo Vega Fernandez
20
+ Jimenez Ruiz Diaz Moreno Alvarez Munoz Romero Gutierrez Navarro Torres
21
+ Vazquez Ramos Serrano Castro Molina Morales Ortega Delgado Rubio Iglesias
22
+ Santos Castillo Cruz Nunez Garrido Medina Lozano Leon
23
+ )
24
+
25
+ MxFormats = [
26
+ Proc.new { [ mx_prefix, mx_first_name_f, mx_last_name ] },
27
+ Proc.new { [ mx_prefix, mx_first_name_m, mx_last_name ] },
28
+ Proc.new { [ mx_first_name_f, mx_last_name ] },
29
+ Proc.new { [ mx_first_name_f, mx_last_name ] },
30
+ Proc.new { [ mx_first_name_f, mx_last_name ] },
31
+ Proc.new { [ mx_first_name_f, mx_last_name ] },
32
+ Proc.new { [ mx_first_name_m, mx_last_name ] },
33
+ Proc.new { [ mx_first_name_m, mx_last_name ] },
34
+ Proc.new { [ mx_first_name_m, mx_last_name ] },
35
+ Proc.new { [ mx_first_name_m, mx_last_name ] }
36
+ ]
37
+
38
+ MX_PREFIXES = {
39
+ :female => %w(Sra. Srta. Dr. Prof.),
40
+ :male => %w(Sr. Dr. Prof.)
41
+ }
42
+
43
+ class << self
44
+ # Returns a random full name using any of _MxFormats_.
45
+ def mx_name
46
+ MxFormats.rand.call.join ' '
47
+ end
48
+
49
+ # Returns a random first name.
50
+ def mx_first_name(gender = nil, double = false)
51
+ gender ||= [ :male, :female ].rand
52
+ name = MX_NAMES[gender].rand
53
+ name += ' ' + MX_NAMES[gender].rand if double
54
+ name
55
+ end
56
+
57
+ # Returns a random female first name.
58
+ def mx_first_name_f(double = false)
59
+ mx_first_name(:female, double)
60
+ end
61
+
62
+ # Returns a random male first name.
63
+ def mx_first_name_m(double = false)
64
+ mx_first_name(:male, double)
65
+ end
66
+
67
+ # Returns a random last name.
68
+ def mx_last_name(double = false)
69
+ name = MX_LAST_NAMES.rand
70
+ name += ' ' + MX_LAST_NAMES.rand if double
71
+ name
72
+ end
73
+
74
+ # Returns a random prefix.
75
+ def mx_prefix(gender = nil)
76
+ gender ||= [ :male, :female ].rand
77
+ MX_PREFIXES[gender].rand
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,4 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'faker'
3
+ require 'faker_es_mx/address'
4
+ require 'faker_es_mx/name'