Class: Faker::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/faker_es_mx/address.rb

Constant Summary collapse

MX_STATES =
{
  :AGU => { :abbr => 'Ags',   :post_codes => 20..20, :name => 'Aguascalientes' },
  :BCN => { :abbr => 'BC',    :post_codes => 21..22, :name => 'Baja California' },
  :BCS => { :abbr => 'BCS',   :post_codes => 23..23, :name => 'Baja California Sur' },
  :CAM => { :abbr => 'Camp',  :post_codes => 24..24, :name => 'Campeche' },
  :COA => { :abbr => 'Coah',  :post_codes => 25..27, :name => 'Coahuila' },
  :COL => { :abbr => 'Col',   :post_codes => 28..28, :name => 'Colima' },
  :CHP => { :abbr => 'Chis',  :post_codes => 29..30, :name => 'Chiapas' },
  :CHH => { :abbr => 'Chih',  :post_codes => 31..33, :name => 'Chihuahua' },
  :DIF => { :abbr => 'DF',    :post_codes => 00..16, :name => 'Distrito Federal' },
  :DUR => { :abbr => 'Dgo',   :post_codes => 34..35, :name => 'Durango' },
  :GUA => { :abbr => 'Gto',   :post_codes => 36..38, :name => 'Guanajuato' },
  :GRO => { :abbr => 'Gro',   :post_codes => 39..41, :name => 'Guerrero' },
  :HID => { :abbr => 'Hgo',   :post_codes => 42..43, :name => 'Hidalgo' },
  :JAL => { :abbr => 'Jal',   :post_codes => 44..48, :name => 'Jalisco' },
  :MEX => { :abbr => 'Mex',   :post_codes => 50..57, :name => 'Estado de México' },
  :MIC => { :abbr => 'Mich',  :post_codes => 58..61, :name => 'Michoacán' },
  :MOR => { :abbr => 'Mor',   :post_codes => 62..62, :name => 'Morelos' },
  :NAY => { :abbr => 'Nay',   :post_codes => 63..63, :name => 'Nayarit' },
  :NLE => { :abbr => 'NL',    :post_codes => 64..67, :name => 'Nuevo León' },
  :OAX => { :abbr => 'Oax',   :post_codes => 68..71, :name => 'Oaxaca' },
  :PUE => { :abbr => 'Pue',   :post_codes => 72..75, :name => 'Puebla' },
  :QUE => { :abbr => 'Qro',   :post_codes => 76..76, :name => 'Querétaro' },
  :ROO => { :abbr => 'QRoo',  :post_codes => 77..77, :name => 'Quintana Roo' },
  :SLP => { :abbr => 'SLP',   :post_codes => 78..79, :name => 'San Luis Potosí' },
  :SIN => { :abbr => 'Sin',   :post_codes => 80..82, :name => 'Sinaloa' },
  :SON => { :abbr => 'Son',   :post_codes => 83..85, :name => 'Sonora' },
  :TAB => { :abbr => 'Tab',   :post_codes => 86..86, :name => 'Tabasco' },
  :TAM => { :abbr => 'Tamps', :post_codes => 87..89, :name => 'Tamaulipas' },
  :TLA => { :abbr => 'Tlax',  :post_codes => 90..90, :name => 'Tlaxcala' },
  :VER => { :abbr => 'Ver',   :post_codes => 91..96, :name => 'Veracruz' },
  :YUC => { :abbr => 'Yuc',   :post_codes => 97..97, :name => 'Yucatán' },
  :ZAC => { :abbr => 'Zac',   :post_codes => 98..99, :name => 'Zacatecas'}
}
MX_LOCALITY_PREFIXES =
%w(Col. Col. Col. Col. Pueblo)

Class Method Summary collapse

Class Method Details

.mx_cities(state) ⇒ Object

Return an array with all the cities on the specified state.



89
90
91
# File 'lib/faker_es_mx/address.rb', line 89

def mx_cities(state)
  @mx_cities[state]
end

.mx_city(state = nil) ⇒ Object

Return a random city. Specify state ISO code to return a valid city for a given state.



83
84
85
86
# File 'lib/faker_es_mx/address.rb', line 83

def mx_city(state = nil)
  state ||= @mx_states_iso.rand
  @mx_cities[state].rand
end

.mx_postcode(state = nil) ⇒ Object

Returns a five digit postal code. Use the iso parameter to generate a valid post code for the specified ISO state.

mx_postcode(mx_state_abbr_iso)


75
76
77
78
79
# File 'lib/faker_es_mx/address.rb', line 75

def mx_postcode(state = nil)
  state ||= @mx_states_iso.rand
  code = MX_STATES[state][:post_codes].to_a.rand
  "%05d" % (code * 1000 + rand(1000))
end

.mx_secondary_addressObject

Return a random secondary address.



113
114
115
# File 'lib/faker_es_mx/address.rb', line 113

def mx_secondary_address
  "%s %s" % [MX_LOCALITY_PREFIXES.rand, mx_city]
end

.mx_state(iso = nil) ⇒ Object

Returns a state in Mexico. Optionally ask for a specific state by its ISO code.



54
55
56
57
# File 'lib/faker_es_mx/address.rb', line 54

def mx_state(iso = nil)
  iso ||= @mx_states_iso.rand
  MX_STATES[iso][:name]
end

.mx_state_abbr(iso = nil) ⇒ Object

Returns the abbreviation of a state according to INEGI. Optionally ask for a specific state by its ISO code.



61
62
63
64
# File 'lib/faker_es_mx/address.rb', line 61

def mx_state_abbr(iso = nil)
  iso ||= @mx_states_iso.rand
  MX_STATES[iso][:abbr]
end

.mx_state_abbr_isoObject

Returns the abbreviation of a state by its ISO code.



67
68
69
# File 'lib/faker_es_mx/address.rb', line 67

def mx_state_abbr_iso
  @mx_states_iso.rand.to_s
end

.mx_street_address(include_secondary = false) ⇒ Object

Return a random full street address (with optional secondary address).



104
105
106
107
108
109
110
# File 'lib/faker_es_mx/address.rb', line 104

def mx_street_address(include_secondary = false)
  Faker.numerify([
    '%s %s No. ####' % [mx_street_prefix, mx_street_name],
    '%s %s No. ###' % [mx_street_prefix, mx_street_name],
    '%s %s No. ##' % [mx_street_prefix, mx_street_name]
  ].rand + (include_secondary ? ' ' + mx_secondary_address : ''))
end

.mx_street_nameObject

Return a random street name.



94
95
96
# File 'lib/faker_es_mx/address.rb', line 94

def mx_street_name
  mx_city
end

.mx_street_prefixObject

Return a random street prefix.



99
100
101
# File 'lib/faker_es_mx/address.rb', line 99

def mx_street_prefix
  %w(Av. Calle Via Priv. Ret. Cerrada Canal Eje).rand
end