Class: Ryba::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/ryba/address.rb

Constant Summary collapse

BuildingFormats =
[
  [ 'д. #', 90 ],
  [ 'д.#', 80 ],
  [ 'д. #/?', 15 ],
  [ 'д. #к?', 10 ],
  [ 'стр. #', 10 ],
  [ 'д.#/?', 5 ],
  [ 'д.#к?', 5 ],
  [ 'стр.#', 5 ],
].freeze
ApartmentFormats =
[
  [ 'кв. #', 10 ],
  [ 'оф. #', 10 ],
  [ '? этаж', 2 ],
  [ 'кв.#', 5 ],
  [ 'оф.#', 5 ],
  [ '?-й эт.', 1 ],
]

Class Method Summary collapse

Class Method Details

.addressObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ryba/address.rb', line 50

def address
  building  = Ryba.pick(1..200)
  apartment = Ryba.pick(1..300)
  separator = Ryba.pick([' ', ', '])

  street + separator +
    if rand(10) < 2
      "#{building}-#{apartment}"
    else
      formatter = lambda do |fmts, num|
        Ryba.weighted_pick(fmts).gsub('#', num.to_s).gsub('?', Ryba.pick(1..9).to_s)
      end

      building  = formatter.call(BuildingFormats, building)
      apartment = formatter.call(ApartmentFormats, apartment)

      "#{building}#{separator}#{apartment}"
    end
end

.cityObject



9
10
11
# File 'lib/ryba/address.rb', line 9

def city
  Ryba.pick(Data::AllCities).gsub('_', ' ')
end

.full_cityObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ryba/address.rb', line 13

def full_city
  cty = Ryba.pick(Data::AllCities)
  h_cty = cty.gsub('_', ' ')

  region = Ryba.pick(Data::RegionByCities[cty])

  if Data::CitiesByRegion[region].first == cty
    "г. #{h_cty}"
  else
    "#{region}, г. #{h_cty}"
  end
end

.indexObject



5
6
7
# File 'lib/ryba/address.rb', line 5

def index
  Ryba.pick(100000...700000)
end

.postalObject



70
71
72
# File 'lib/ryba/address.rb', line 70

def postal
  "#{index}, #{full_city}, #{address}"
end

.streetObject



26
27
28
# File 'lib/ryba/address.rb', line 26

def street
  Ryba.pick(Data::StreetNames)
end