Module: FFaker::Address

Constant Summary collapse

COMPASS_DIRECTIONS =
%w[North East West South].freeze
CITY_PREFIXES =
COMPASS_DIRECTIONS + %w[New Lake Port]
SEC_ADDR =
['Apt. ###', 'Suite ###'].freeze

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, luhn_check, underscore, unique

Methods included from RandomUtils

#fetch_sample, #rand, #shuffle

Instance Method Details

#building_numberObject



50
51
52
# File 'lib/ffaker/address.rb', line 50

def building_number
  FFaker.numerify(('#' * rand(3..5)))
end

#cityObject



37
38
39
40
41
42
43
44
# File 'lib/ffaker/address.rb', line 37

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

#city_prefixObject

end US deprecation



29
30
31
# File 'lib/ffaker/address.rb', line 29

def city_prefix
  fetch_sample(CITY_PREFIXES)
end

#city_suffixObject



33
34
35
# File 'lib/ffaker/address.rb', line 33

def city_suffix
  fetch_sample(CITY_SUFFIXES)
end

#country(given_code = nil) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/ffaker/address.rb', line 93

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

#country_code(given_country = nil) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/ffaker/address.rb', line 102

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

#neighborhoodObject

end UK deprecation



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

def neighborhood
  fetch_sample(NEIGHBORHOOD)
end

#secondary_addressObject



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

def secondary_address
  FFaker.numerify(fetch_sample(SEC_ADDR))
end

#street_address(include_secondary = false) ⇒ Object



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

def street_address(include_secondary = false)
  str = +"#{building_number} #{street_name}"
  str << " #{secondary_address}" if include_secondary
  str
end

#street_nameObject



54
55
56
57
58
59
# File 'lib/ffaker/address.rb', line 54

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

#street_suffixObject



46
47
48
# File 'lib/ffaker/address.rb', line 46

def street_suffix
  fetch_sample(STREET_SUFFIX)
end

#time_zoneObject



111
112
113
# File 'lib/ffaker/address.rb', line 111

def time_zone
  fetch_sample(TIME_ZONE)
end

#uk_countryObject



78
79
80
81
# File 'lib/ffaker/address.rb', line 78

def uk_country
  warn '[uk_country] is deprecated. For UK addresses please use the AddressUK module'
  FFaker::AddressUK.country
end

#uk_countyObject

Deprecated.

UK specific address info. Moved into FFaker::AddressUK

UK Variants



73
74
75
76
# File 'lib/ffaker/address.rb', line 73

def uk_county
  warn '[uk_county] is deprecated. For UK addresses please use the AddressUK module'
  FFaker::AddressUK.county
end

#uk_postcodeObject



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

def uk_postcode
  warn '[uk_postcode] is deprecated. For UK addresses please use the AddressUK module'
  FFaker::AddressUK.postcode
end

#us_stateObject



18
19
20
21
# File 'lib/ffaker/address.rb', line 18

def us_state
  warn '[us_state] is deprecated. For US addresses please use the AddressUS module'
  FFaker::AddressUS.state
end

#us_state_abbrObject



23
24
25
26
# File 'lib/ffaker/address.rb', line 23

def us_state_abbr
  warn '[state_abbr] is deprecated. For US addresses please use the AddressUS module'
  FFaker::AddressUS.state_abbr
end

#zip_codeObject

Deprecated.

US specific address info. Moved into FFaker::AddressUS



13
14
15
16
# File 'lib/ffaker/address.rb', line 13

def zip_code
  warn '[zip_code] is deprecated. For US addresses please use the AddressUS module'
  FFaker::AddressUS.zip_code
end