From 87578bb84ae9b6568c9932b8d056c638639d3f9a Mon Sep 17 00:00:00 2001 From: Benjamin Curtis Date: Wed, 2 Jan 2008 01:03:09 +0000 Subject: [PATCH] Added secondary_address for suite and apartment numbers. New option for street_address to determine whether to return the secondary address (defaults to false). --- lib/faker/address.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/faker/address.rb b/lib/faker/address.rb index 81187160ad..aef1988cc2 100644 --- a/lib/faker/address.rb +++ b/lib/faker/address.rb @@ -24,15 +24,19 @@ def street_name ].rand.call end - def street_address + def street_address(include_secondary = false) Faker.numerify([ - Proc.new { '##### %s' % street_name }, - Proc.new { '##### %s' % street_name }, - Proc.new { '##### %s' % street_name }, - Proc.new { '##### %s' % street_name }, - Proc.new { '##### %s Apt. ###' % street_name }, - Proc.new { '##### %s Suite ###' % street_name } - ].rand.call) + '##### %s' % street_name, + '#### %s' % street_name, + '### %s' % street_name + ].rand + (include_secondary ? ' ' + secondary_address : '')) + end + + def secondary_address + Faker.numerify([ + 'Apt. ###', + 'Suite ###' + ].rand) end # UK Variants @@ -46,9 +50,9 @@ def uk_country def uk_postcode Faker.bothify([ - Proc.new { '??# #??' }, - Proc.new { '??## #??' } - ].rand.call).upcase + '??# #??', + '??## #??' + ].rand).upcase end end end