1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
# frozen_string_literal: true
module FFaker
module Address
extend ModuleUtils
extend self
COMPASS_DIRECTIONS = %w[North East West South].freeze
CITY_PREFIXES = COMPASS_DIRECTIONS + %w[New Lake Port]
SEC_ADDR = ['Apt. ###', 'Suite ###'].freeze
# @deprecated US specific address info. Moved into {AddressUS}
def zip_code
warn '[zip_code] is deprecated. For US addresses please use the AddressUS module'
FFaker::AddressUS.zip_code
end
def us_state
warn '[us_state] is deprecated. For US addresses please use the AddressUS module'
FFaker::AddressUS.state
end
def us_state_abbr
warn '[state_abbr] is deprecated. For US addresses please use the AddressUS module'
FFaker::AddressUS.state_abbr
end
# end US deprecation
def city_prefix
fetch_sample(CITY_PREFIXES)
end
def city_suffix
fetch_sample(CITY_SUFFIXES)
end
def city
case rand(0..3)
when 0 then "#{city_prefix} #{Name.first_name}#{city_suffix}"
when 1 then "#{city_prefix} #{Name.first_name}"
when 2 then "#{Name.first_name}#{city_suffix}"
when 3 then "#{Name.last_name}#{city_suffix}"
end
end
def street_suffix
fetch_sample(STREET_SUFFIX)
end
def building_number
FFaker.numerify(('#' * rand(3..5)))
end
def street_name
case rand(0..1)
when 0 then "#{Name.last_name} #{street_suffix}"
when 1 then "#{Name.first_name} #{street_suffix}"
end
end
def street_address(include_secondary = false)
str = +"#{building_number} #{street_name}"
str << " #{secondary_address}" if include_secondary
str
end
def secondary_address
FFaker.numerify(fetch_sample(SEC_ADDR))
end
# @deprecated UK specific address info. Moved into {AddressUK}
# UK Variants
def uk_county
warn '[uk_county] is deprecated. For UK addresses please use the AddressUK module'
FFaker::AddressUK.county
end
def uk_country
warn '[uk_country] is deprecated. For UK addresses please use the AddressUK module'
FFaker::AddressUK.country
end
def uk_postcode
warn '[uk_postcode] is deprecated. For UK addresses please use the AddressUK module'
FFaker::AddressUK.postcode
end
# end UK deprecation
def neighborhood
fetch_sample(NEIGHBORHOOD)
end
def country(given_code = nil)
country_index = COUNTRY_CODE.index(given_code)
if given_code && country_index
COUNTRY[country_index]
else
fetch_sample(COUNTRY)
end
end
def country_code(given_country = nil)
code_index = COUNTRY.index(given_country)
if given_country && code_index
COUNTRY_CODE[code_index]
else
fetch_sample(COUNTRY_CODE)
end
end
def time_zone
fetch_sample(TIME_ZONE)
end
end
end
|