Skip to content

Instantly share code, notes, and snippets.

@Bodacious
Created January 24, 2012 20:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Bodacious/1672379 to your computer and use it in GitHub Desktop.
Save Bodacious/1672379 to your computer and use it in GitHub Desktop.
New York Address generator

NY Address Generator

60% of the time it works EVERY time!

Installing

  gem 'ny_address', git: 'git://gist.github.com/1672379.git'

Using

NYAddress.random # => "4778 38th Street, New York, NY"
Gem::Specification.new do |s|
s.name = 'ny_address'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'Gavin Morrice'
s.email = 'gavin@katanacode.com'
s.summary = 'Generates a random, valid, NYC address.'
s.description = 'Generates a random, valid, NYC address - It\'s reasonably accurate and suitable for testing!'
s.files = ['ny_address.rb']
s.test_file = 'ny_address_spec.rb'
s.require_path = '.'
s.add_development_dependency('rspec', ["~> 2.0"])
end
module NYAddress
begin
require 'active_support/inflector'
extend ActiveSupport::Inflector
rescue LoadError
warn "ActiveSupport is required for ny_address - please ensure it's installed"
end
def self.random
"#{rand(5000).ceil} #{ordinalize(rand(110).ceil)} Street, New York, NY"
end
end
require File.expand_path('ny_address')
describe NYAddress do
describe :random do
it "returns a valid looking address" do
REGEX = /\d{1,4}\s\d{1,3}(st|nd|rd|th)\sStreet,\sNew\sYork,\sNY/
NYAddress.random.should match(REGEX)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment