Sha256: 5684d32d26699307b0d19c96e3f0c6ef18ae82d0c6f50a6c1f7e710171ca7401
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
# encoding: utf-8 module Belka class Address class<<self def index Belka.pick(100000...700000) end def city Belka.pick(Data::AllCities).gsub('_', ' ') end def full_city cty = Belka.pick(Data::AllCities) h_cty = cty.gsub('_', ' ') region = Belka.pick(Data::RegionByCities[cty]) if Data::CitiesByRegion[region].first == cty "г. #{h_cty}" else "#{region}, г. #{h_cty}" end end def street Belka.pick(Data::StreetNames) end BuildingFormats = [ [ 'д. #', 90 ], [ 'д.#', 80 ], [ 'д. #/?', 15 ], [ 'д. #к?', 10 ], [ 'стр. #', 10 ], [ 'д.#/?', 5 ], [ 'д.#к?', 5 ], [ 'стр.#', 5 ], ].freeze ApartmentFormats = [ [ 'кв. #', 10 ], [ 'оф. #', 10 ], [ '? этаж', 2 ], [ 'кв.#', 5 ], [ 'оф.#', 5 ], [ '?-й эт.', 1 ], ] def address building = Belka.pick(1..200) apartment = Belka.pick(1..300) separator = Belka.pick([' ', ', ']) street + separator + if rand(10) < 2 "#{building}-#{apartment}" else formatter = lambda do |fmts, num| Belka.weighted_pick(fmts).gsub('#', num.to_s).gsub('?', Belka.pick(1..9).to_s) end building = formatter.call(BuildingFormats, building) apartment = formatter.call(ApartmentFormats, apartment) "#{building}#{separator}#{apartment}" end end def postal "#{index}, #{full_city}, #{address}" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
belka-0.0.2 | lib/belka/address.rb |