Module: FFaker::Address

Constant Summary collapse

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

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore

Instance Method Details

#building_numberObject



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

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

#cityObject



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

def city
  case rand(4)
  when 0 then '%s %s%s' % [city_prefix, Name.first_name, city_suffix]
  when 1 then '%s %s'   % [city_prefix, Name.first_name]
  when 2 then '%s%s'    % [Name.first_name, city_suffix]
  when 3 then '%s%s'    % [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
  CITY_PREFIXES.sample
end

#city_suffixObject



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

def city_suffix
  CITY_SUFFIXES.sample
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
    COUNTRY.sample
  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
    COUNTRY_CODE.sample
  end
end

#neighborhoodObject

end UK deprecation



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

def neighborhood
  NEIGHBORHOOD.sample
end

#secondary_addressObject



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

def secondary_address
  FFaker.numerify(SEC_ADDR.sample)
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(2)
  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
  STREET_SUFFIX.sample
end

#time_zoneObject



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

def time_zone
  TIME_ZONE.sample
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