Skip to content

Instantly share code, notes, and snippets.

@kpeltzer
Forked from Bodacious/README.md
Last active March 6, 2016 21:38
Show Gist options
  • Save kpeltzer/8b144802db9690a71d4d to your computer and use it in GitHub Desktop.
Save kpeltzer/8b144802db9690a71d4d 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(number_of_times)
number_of_times do |i|
"#{rand(5000).ceil} #{ordinalize(rand(200).ceil)} Street, #{rand(9999).ceil + 10000}"
end
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