Sha256: 9629bac31fadf333e9ea28d2682f096c65aff4c9b6e505f1890e356c158604bb

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

module Ryba
  class Address
    class<<self
      def index
        Ryba.pick(100000...700000)
      end

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

      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

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

      BuildingFormats = [
        [ 'д. #', 90 ],
        [ 'д.#', 80 ],
        [ 'д. #/?', 15 ],
        [ 'д. #к?', 10 ],
        [ 'стр. #', 10 ],
        [ 'д.#/?', 5 ],
        [ 'д.#к?', 5 ],
        [ 'стр.#', 5 ],
      ].freeze

      ApartmentFormats = [
        [ 'кв. #', 10 ],
        [ 'оф. #', 10 ],
        [ '? этаж', 2 ],
        [ 'кв.#', 5 ],
        [ 'оф.#', 5 ],
        [ '?-й эт.', 1 ],
      ]

      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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ryba-0.1.1 lib/ryba/address.rb
ryba-0.1.0 lib/ryba/address.rb