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(legacy_options = NOT_GIVEN, 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(legacy_code = NOT_GIVEN, 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(legacy_name = NOT_GIVEN, 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(legacy_include_secondary = NOT_GIVEN, 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(legacy_state_abbreviation = NOT_GIVEN, state_abbreviation: '') ⇒ String
(also: zip, postcode)
Produces a Zip Code.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale
Class Method Details
.building_number ⇒ String
Produces a building number.
82 83 84 |
# File 'lib/faker/default/address.rb', line 82 def building_number bothify(fetch('address.building_number')) end |
.city(legacy_options = NOT_GIVEN, options: {}) ⇒ String
Produces the name of a city.
21 22 23 24 25 26 27 |
# File 'lib/faker/default/address.rb', line 21 def city( = NOT_GIVEN, options: {}) warn_for_deprecated_arguments do |keywords| keywords << :options if != NOT_GIVEN end parse([:with_state] ? 'address.city_with_state' : 'address.city') end |
.city_prefix ⇒ String
Produces a city prefix.
190 191 192 |
# File 'lib/faker/default/address.rb', line 190 def city_prefix fetch('address.city_prefix') end |
.city_suffix ⇒ String
Produces a city suffix.
177 178 179 |
# File 'lib/faker/default/address.rb', line 177 def city_suffix fetch('address.city_suffix') end |
.community ⇒ String
Produces the name of a community.
95 96 97 |
# File 'lib/faker/default/address.rb', line 95 def community parse('address.community') end |
.country ⇒ String
Produces the name of a country.
229 230 231 |
# File 'lib/faker/default/address.rb', line 229 def country fetch('address.country') end |
.country_by_code(legacy_code = NOT_GIVEN, 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.
245 246 247 248 249 250 251 |
# File 'lib/faker/default/address.rb', line 245 def country_by_code(legacy_code = NOT_GIVEN, code: 'US') warn_for_deprecated_arguments do |keywords| keywords << :code if legacy_code != NOT_GIVEN end fetch('address.country_by_code.' + code) end |
.country_code ⇒ String
Produces an ISO 3166 country code.
280 281 282 |
# File 'lib/faker/default/address.rb', line 280 def country_code fetch('address.country_code') end |
.country_code_long ⇒ String
Produces a long (alpha-3) ISO 3166 country code.
293 294 295 |
# File 'lib/faker/default/address.rb', line 293 def country_code_long fetch('address.country_code_long') end |
.country_name_to_code(legacy_name = NOT_GIVEN, name: 'united_states') ⇒ String
Produces an ISO 3166 country code when given a country name.
263 264 265 266 267 268 269 |
# File 'lib/faker/default/address.rb', line 263 def country_name_to_code(legacy_name = NOT_GIVEN, name: 'united_states') warn_for_deprecated_arguments do |keywords| keywords << :name if legacy_name != NOT_GIVEN end fetch('address.country_by_name.' + name) end |
.full_address ⇒ String
Produces a full address.
333 334 335 |
# File 'lib/faker/default/address.rb', line 333 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"}
359 360 361 362 363 364 365 |
# File 'lib/faker/default/address.rb', line 359 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.
306 307 308 |
# File 'lib/faker/default/address.rb', line 306 def latitude ((rand * 180) - 90).to_f end |
.longitude ⇒ Float
Produces a longitude.
319 320 321 |
# File 'lib/faker/default/address.rb', line 319 def longitude ((rand * 360) - 180).to_f end |
.mail_box ⇒ String
Produces a mail box number.
108 109 110 |
# File 'lib/faker/default/address.rb', line 108 def mail_box bothify(fetch('address.mail_box')) end |
.secondary_address ⇒ String
Produces a secondary address.
69 70 71 |
# File 'lib/faker/default/address.rb', line 69 def secondary_address bothify(fetch('address.secondary_address')) end |
.state ⇒ String
Produces the name of a state.
216 217 218 |
# File 'lib/faker/default/address.rb', line 216 def state fetch('address.state') end |
.state_abbr ⇒ String
Produces a state abbreviation.
203 204 205 |
# File 'lib/faker/default/address.rb', line 203 def state_abbr fetch('address.state_abbr') end |
.street_address(legacy_include_secondary = NOT_GIVEN, include_secondary: false) ⇒ String
Produces a street address.
52 53 54 55 56 57 58 |
# File 'lib/faker/default/address.rb', line 52 def street_address(legacy_include_secondary = NOT_GIVEN, include_secondary: false) warn_for_deprecated_arguments do |keywords| keywords << :include_secondary if legacy_include_secondary != NOT_GIVEN end numerify(parse('address.street_address') + (include_secondary ? ' ' + secondary_address : '')) end |
.street_name ⇒ String
Produces a street name.
38 39 40 |
# File 'lib/faker/default/address.rb', line 38 def street_name parse('address.street_name') end |
.street_suffix ⇒ String
Produces a street suffix.
164 165 166 |
# File 'lib/faker/default/address.rb', line 164 def street_suffix fetch('address.street_suffix') end |
.time_zone ⇒ String
Produces the name of a time zone.
148 149 150 |
# File 'lib/faker/default/address.rb', line 148 def time_zone fetch('address.time_zone') end |
.zip_code(legacy_state_abbreviation = NOT_GIVEN, state_abbreviation: '') ⇒ String Also known as: zip, postcode
Produces a Zip Code.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/faker/default/address.rb', line 124 def zip_code(legacy_state_abbreviation = NOT_GIVEN, state_abbreviation: '') warn_for_deprecated_arguments do |keywords| keywords << :state_abbreviation if legacy_state_abbreviation != NOT_GIVEN end if state_abbreviation.empty? letterified_string = letterify(fetch('address.postcode')) return numerify(letterified_string, leading_zero: true) end # provide a zip code that is valid for the state provided # see http://www.fincen.gov/forms/files/us_state_territory_zip_codes.pdf bothify(fetch('address.postcode_by_state.' + state_abbreviation)) end |