Skip to content

Instantly share code, notes, and snippets.

@rdpoor
Created March 1, 2013 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdpoor/5062356 to your computer and use it in GitHub Desktop.
Save rdpoor/5062356 to your computer and use it in GitHub Desktop.
Generate a sequence of fictitious US street addresses for FactoryGirl
FactoryGirl.define do
# generate a sequence of fake US street addresses, such as:
# 1001 Birch Boulevard, Clinton AK 52574, USA
sequence :address do |n|
# NB: the length of street_name, street_type, city, state arrays
# are all chosen to be relatively prime to generate maximal
# length sequences
street_number = 1000 + n
street_name = %w(Aspen Birch Cedar Dogwood Elm Ginkgo Hickory Ironwood
Juniper Linden Maple Oak Palm Quince Redwood Spruce Tulip Willow)[n % 18]
street_type = %w(Avenue Boulevard Drive Place Road Street Way)[n % 7]
city = %w(Franklin Clinton Springfield Greenville Salem Fairview
Madison Washington Georgetown Arlington Ashland Burlington
Manchester Marion Oxford Clayton Jackson Milton Auburn Dayton
Lexington Milford Riverside Cleveland Dover Hudson Kingston Mount\ Vernon
Newport Oakland)[n %31]
state = %w(AL AK AZ AR CA CO CT DE DC FL GA HI ID IL IN IA KS KY LA
ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PW PA RI SC
SD TN TX UT VI VT VA WA WV WI WY)[n % 53]
zip = sprintf("%05d", (1073676287 * (n + 1)) % 100000)
"#{street_number} #{street_name} #{street_type}, #{city} #{state} #{zip}, USA"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment