ivanvr-faker_es_mx 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/faker_es_mx/address.rb +59 -7
- data/lib/mx_cities.txt +2456 -0
- metadata +2 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/faker_es_mx/address.rb
CHANGED
@@ -5,10 +5,10 @@ module Faker
|
|
5
5
|
:BCN => { :abbr => 'BC', :post_codes => 21..22, :name => 'Baja California' },
|
6
6
|
:BCS => { :abbr => 'BCS', :post_codes => 23..23, :name => 'Baja California Sur' },
|
7
7
|
:CAM => { :abbr => 'Camp', :post_codes => 24..24, :name => 'Campeche' },
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
8
|
+
:COA => { :abbr => 'Coah', :post_codes => 25..27, :name => 'Coahuila' },
|
9
|
+
:COL => { :abbr => 'Col', :post_codes => 28..28, :name => 'Colima' },
|
10
|
+
:CHP => { :abbr => 'Chis', :post_codes => 29..30, :name => 'Chiapas' },
|
11
|
+
:CHH => { :abbr => 'Chih', :post_codes => 31..33, :name => 'Chihuahua' },
|
12
12
|
:DIF => { :abbr => 'DF', :post_codes => 00..16, :name => 'Distrito Federal' },
|
13
13
|
:DUR => { :abbr => 'Dgo', :post_codes => 34..35, :name => 'Durango' },
|
14
14
|
:GUA => { :abbr => 'Gto', :post_codes => 36..38, :name => 'Guanajuato' },
|
@@ -37,6 +37,17 @@ module Faker
|
|
37
37
|
|
38
38
|
@mx_states_iso = MX_STATES.keys
|
39
39
|
|
40
|
+
# Is this the right approach?
|
41
|
+
mx_cities_txt = File.join(File.dirname(__FILE__), '..', 'mx_cities.txt')
|
42
|
+
@mx_cities = {}
|
43
|
+
@mx_states_iso.each {|c| @mx_cities[c] = [] }
|
44
|
+
File.read(mx_cities_txt).split("\n").collect do |st_cty|
|
45
|
+
state, city = st_cty.split('|')
|
46
|
+
@mx_cities[state.to_sym] << city
|
47
|
+
end
|
48
|
+
|
49
|
+
MX_LOCALITY_PREFIXES = %w(Col. Col. Col. Col. Pueblo)
|
50
|
+
|
40
51
|
class << self
|
41
52
|
# Returns a state in Mexico.
|
42
53
|
# Optionally ask for a specific state by its ISO code.
|
@@ -61,11 +72,52 @@ module Faker
|
|
61
72
|
# Use the iso parameter to generate a valid
|
62
73
|
# post code for the specified ISO state.
|
63
74
|
# mx_postcode(mx_state_abbr_iso)
|
64
|
-
def mx_postcode(
|
65
|
-
|
66
|
-
code = MX_STATES[
|
75
|
+
def mx_postcode(state = nil)
|
76
|
+
state ||= @mx_states_iso.rand
|
77
|
+
code = MX_STATES[state][:post_codes].to_a.rand
|
67
78
|
"%05d" % (code * 1000 + rand(1000))
|
68
79
|
end
|
80
|
+
|
81
|
+
# Return a random city. Specify state ISO code to return a valid
|
82
|
+
# city for a given state.
|
83
|
+
def mx_city(state = nil)
|
84
|
+
state ||= @mx_states_iso.rand
|
85
|
+
@mx_cities[state].rand
|
86
|
+
end
|
87
|
+
|
88
|
+
# Return an array with all the cities on the specified state.
|
89
|
+
def mx_cities(state)
|
90
|
+
@mx_cities[state]
|
91
|
+
end
|
92
|
+
|
93
|
+
# Return a random street name.
|
94
|
+
def mx_street_name
|
95
|
+
mx_city
|
96
|
+
end
|
97
|
+
|
98
|
+
# Return a random street prefix.
|
99
|
+
def mx_street_prefix
|
100
|
+
%w(Av. Calle Via Priv. Ret. Cerrada Canal Eje).rand
|
101
|
+
end
|
102
|
+
|
103
|
+
# Return a random full street address (with optional secondary address).
|
104
|
+
def mx_street_address(include_secondary = false)
|
105
|
+
Faker.numerify([
|
106
|
+
'%s %s No. ####' % [mx_street_prefix, mx_street_name],
|
107
|
+
'%s %s No. ###' % [mx_street_prefix, mx_street_name],
|
108
|
+
'%s %s No. ##' % [mx_street_prefix, mx_street_name]
|
109
|
+
].rand + (include_secondary ? ' ' + mx_secondary_address : ''))
|
110
|
+
end
|
111
|
+
|
112
|
+
# Return a random secondary address.
|
113
|
+
def mx_secondary_address
|
114
|
+
"%s %s" % [MX_LOCALITY_PREFIXES.rand, mx_city]
|
115
|
+
end
|
116
|
+
|
117
|
+
# Return a random phone number.
|
118
|
+
def mx_phone_number
|
119
|
+
Faker.numerify(['(###) #### ####', '(##) #### ####'].rand)
|
120
|
+
end
|
69
121
|
end
|
70
122
|
end
|
71
123
|
end
|