Sha256: 0bf1eed0bc04c59ac33dec6dad5739e71d3ca103a3e6300f63de031d71ff2c68

Contents?: true

Size: 511 Bytes

Versions: 1

Compression:

Stored size: 511 Bytes

Contents

module Geonames
  module Data
    class NameIndex
      def initialize(features)
        @index = features.inject({}) do |index, feature|
          feature.names.map(&:downcase).inject(index) do |index, name|
            index[name] ||= []
            index[name].push(feature).uniq!
            index
          end
        end
      end

      def [](name)
        @index[name.downcase]
      end

      def self.load(filepath, &filter)
        new(Feature.load(filepath, &filter))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geonames-data-0.1.1 lib/geonames/data/name_index.rb