Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 24c4b37f1c
Fetching contributors…

Cannot retrieve contributors at this time

file 30 lines (23 sloc) 0.574 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
module StreetNames
  class Finder
    attr_reader :streets

    def initialize locale=LOCALE
      @database = StreetNames::Database.new locale
      convert!
    end

    [ :postcode, :name, :area ].each do |key|
      define_method(:"find_by_#{key}") do |value|
        @streets.select { |street| eval("street.#{key}") == value }
      end
    end

    def all
      @streets
    end

    private

    def convert!
      @streets = @database.load_streets.map do |street|
        Street.new [ street[:name], street[:postcode], street[:area] ]
      end
    end


  end
end
Something went wrong with that request. Please try again.