Class: FauxData::AddressGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/faux_data/address_generator.rb

Instance Method Summary collapse

Constructor Details

#initializeAddressGenerator

Returns a new instance of AddressGenerator.



6
7
8
9
10
11
# File 'lib/faux_data/address_generator.rb', line 6

def initialize 
  @city_state_zipcodes = Array.new
  @street_names = Array.new
  @filename_city_state_zip = File.join(File.dirname(__FILE__),'data','us','city_state_zipcode.txt')
  @filename_street_names = File.join(File.dirname(__FILE__),'data','us','street_names_top_1500.txt')
end

Instance Method Details

#addressObject



13
14
15
16
17
18
19
20
21
# File 'lib/faux_data/address_generator.rb', line 13

def address
  load_csz_file if @city_state_zipcodes.size < 1
  load_street_file if @street_names.size < 1
  street = "#{rand(9899) + 100} #{@street_names.choice[:street]}".strip
  if rand(5) == 4 # 20 % of the time
      street << ", Apt ##{(100..999).to_a.choice}"
  end
  return @city_state_zipcodes.choice.merge({:street => street.upcase.strip})
end