Class: Faker::Address
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.building_number ⇒ String
Produces a building number.
-
.city(options: {}) ⇒ String
Produces the name of a city.
-
.city_prefix ⇒ String
Produces a city prefix.
-
.city_suffix ⇒ String
Produces a city suffix.
-
.community ⇒ String
Produces the name of a community.
-
.country ⇒ String
Produces the name of a country.
-
.country_by_code(code: 'US') ⇒ String
Produces a country by ISO country code.
-
.country_code ⇒ String
Produces an ISO 3166 country code.
-
.country_code_long ⇒ String
Produces a long (alpha-3) ISO 3166 country code.
-
.country_name_to_code(name: 'united_states') ⇒ String
Produces an ISO 3166 country code when given a country name.
-
.full_address ⇒ String
Produces a full address.
-
.full_address_as_hash(*attrs, **attrs_params) ⇒ Hash
Produces Address hash of required fields.
-
.latitude ⇒ Float
Produces a latitude.
-
.longitude ⇒ Float
Produces a longitude.
-
.mail_box ⇒ String
Produces a mail box number.
-
.secondary_address ⇒ String
Produces a secondary address.
-
.state ⇒ String
Produces the name of a state.
-
.state_abbr ⇒ String
Produces a state abbreviation.
-
.street_address(include_secondary: false) ⇒ String
Produces a street address.
-
.street_name ⇒ String
Produces a street name.
-
.street_suffix ⇒ String
Produces a street suffix.
-
.time_zone ⇒ String
Produces the name of a time zone.
-
.zip_code(state_abbreviation: '') ⇒ String
(also: zip, postcode)
Produces a Zip Code.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale
Class Method Details
.building_number ⇒ String
Produces a building number.
74 75 76 |
# File 'lib/faker/default/address.rb', line 74 def building_number bothify(fetch('address.building_number')) end |
.city(options: {}) ⇒ String
Produces the name of a city.
21 22 23 |
# File 'lib/faker/default/address.rb', line 21 def city(options: {}) parse([:with_state] ? 'address.city_with_state' : 'address.city') end |
.city_prefix ⇒ String
Produces a city prefix.
178 179 180 |
# File 'lib/faker/default/address.rb', line 178 def city_prefix fetch('address.city_prefix') end |
.city_suffix ⇒ String
Produces a city suffix.
165 166 167 |
# File 'lib/faker/default/address.rb', line 165 def city_suffix fetch('address.city_suffix') end |
.community ⇒ String
Produces the name of a community.
87 88 89 |
# File 'lib/faker/default/address.rb', line 87 def community parse('address.community') end |
.country ⇒ String
Produces the name of a country.
217 218 219 |
# File 'lib/faker/default/address.rb', line 217 def country fetch('address.country') end |
.country_by_code(code: 'US') ⇒ String
Produces a country by ISO country code. See the [List of ISO 3166 country codes](en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) on Wikipedia for a full list.
233 234 235 |
# File 'lib/faker/default/address.rb', line 233 def country_by_code(code: 'US') fetch("address.country_by_code.#{code}") end |
.country_code ⇒ String
Produces an ISO 3166 country code.
260 261 262 |
# File 'lib/faker/default/address.rb', line 260 def country_code fetch('address.country_code') end |
.country_code_long ⇒ String
Produces a long (alpha-3) ISO 3166 country code.
273 274 275 |
# File 'lib/faker/default/address.rb', line 273 def country_code_long fetch('address.country_code_long') end |
.country_name_to_code(name: 'united_states') ⇒ String
Produces an ISO 3166 country code when given a country name.
247 248 249 |
# File 'lib/faker/default/address.rb', line 247 def country_name_to_code(name: 'united_states') fetch("address.country_by_name.#{name}") end |
.full_address ⇒ String
Produces a full address.
313 314 315 |
# File 'lib/faker/default/address.rb', line 313 def full_address parse('address.full_address') end |
.full_address_as_hash(*attrs, **attrs_params) ⇒ Hash
Produces Address hash of required fields
Faker::Address.full_address_as_hash(:full_address)
#=> {:full_address=>"87635 Rice Street, Lake Brentonton, OR 61896-5968"}
Faker::Address.full_address_as_hash(:city, :time_zone)
#=> {:city=>"East Faustina", :time_zone=>"America/Mexico_City"}
Faker::Address.full_address_as_hash(:street_address, street_address: {include_secondary: true})
#=> {:street_address=>"29423 Kenneth Causeway Suite 563"}
339 340 341 342 343 344 345 |
# File 'lib/faker/default/address.rb', line 339 def full_address_as_hash(*attrs, **attrs_params) attrs.map!(&:to_sym) attrs_params.transform_keys!(&:to_sym) attrs.map do |attr| { "#{attr}": attrs_params[attr] ? send(attr, **attrs_params[attr]) : send(attr) } end.reduce({}, :merge) end |
.latitude ⇒ Float
Produces a latitude.
286 287 288 |
# File 'lib/faker/default/address.rb', line 286 def latitude ((rand * 180) - 90).to_f end |
.longitude ⇒ Float
Produces a longitude.
299 300 301 |
# File 'lib/faker/default/address.rb', line 299 def longitude ((rand * 360) - 180).to_f end |
.mail_box ⇒ String
Produces a mail box number.
100 101 102 |
# File 'lib/faker/default/address.rb', line 100 def mail_box bothify(fetch('address.mail_box')) end |
.secondary_address ⇒ String
Produces a secondary address.
61 62 63 |
# File 'lib/faker/default/address.rb', line 61 def secondary_address bothify(fetch('address.secondary_address')) end |
.state ⇒ String
Produces the name of a state.
204 205 206 |
# File 'lib/faker/default/address.rb', line 204 def state fetch('address.state') end |
.state_abbr ⇒ String
Produces a state abbreviation.
191 192 193 |
# File 'lib/faker/default/address.rb', line 191 def state_abbr fetch('address.state_abbr') end |
.street_address(include_secondary: false) ⇒ String
Produces a street address.
48 49 50 |
# File 'lib/faker/default/address.rb', line 48 def street_address(include_secondary: false) numerify(parse('address.street_address') + (include_secondary ? " #{secondary_address}" : '')) end |
.street_name ⇒ String
Produces a street name.
34 35 36 |
# File 'lib/faker/default/address.rb', line 34 def street_name parse('address.street_name') end |
.street_suffix ⇒ String
Produces a street suffix.
152 153 154 |
# File 'lib/faker/default/address.rb', line 152 def street_suffix fetch('address.street_suffix') end |
.time_zone ⇒ String
Produces the name of a time zone.
136 137 138 |
# File 'lib/faker/default/address.rb', line 136 def time_zone fetch('address.time_zone') end |
.zip_code(state_abbreviation: '') ⇒ String Also known as: zip, postcode
Produces a Zip Code.
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/faker/default/address.rb', line 116 def zip_code(state_abbreviation: '') if state_abbreviation.empty? letterified_string = letterify(fetch('address.postcode')) return numerify(letterified_string, leading_zero: true) end # provide a zip code that may be valid for the state provided # note: zip code may appear in the correct format for the state provided but may not be an actual state zip. bothify(fetch("address.postcode_by_state.#{state_abbreviation}")) end |