Sha256: e0a1f6ed2145d4640ce8ab9ab9fac3bf8dee468d73549acdcf57c3f0f4359fa9

Contents?: true

Size: 1.71 KB

Versions: 9

Compression:

Stored size: 1.71 KB

Contents

require 'geocoder/results/base'

module Geocoder::Result
  class Nominatim < Base

    def poi
      %w[building university school hospital mall hotel restaurant stadium bus_stop tram_stop].each do |key|
        return @data['address'][key] if @data['address'].key?(key)
      end
      return nil
    end

    def house_number
      @data['address']['house_number']
    end

    def address
      @data['display_name']
    end

    def street
      %w[road pedestrian highway].each do |key|
        return @data['address'][key] if @data['address'].key?(key)
      end
      return nil
    end

    def city
      %w[city town village hamlet].each do |key|
        return @data['address'][key] if @data['address'].key?(key)
      end
      return nil
    end

    def village
      @data['address']['village']
    end

    def town
      @data['address']['town']
    end

    def state
      @data['address']['state']
    end

    alias_method :state_code, :state

    def postal_code
      @data['address']['postcode']
    end

    def county
      @data['address']['county']
    end

    def country
      @data['address']['country']
    end

    def country_code
      @data['address']['country_code']
    end

    def suburb
      @data['address']['suburb']
    end

    def coordinates
      [@data['lat'].to_f, @data['lon'].to_f]
    end

    def place_class
      @data['class']
    end

    def place_type
      @data['type']
    end

    def self.response_attributes
      %w[place_id osm_type osm_id boundingbox license
         polygonpoints display_name class type stadium]
    end

    response_attributes.each do |a|
      unless method_defined?(a)
        define_method a do
          @data[a]
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
geocoder-1.3.0 lib/geocoder/results/nominatim.rb
geocoder-1.2.14 lib/geocoder/results/nominatim.rb
geocoder-1.2.13 lib/geocoder/results/nominatim.rb
geocoder-1.2.12 lib/geocoder/results/nominatim.rb
geocoder-1.2.11 lib/geocoder/results/nominatim.rb
geocoder-1.2.10 lib/geocoder/results/nominatim.rb
geocoder-1.2.9 lib/geocoder/results/nominatim.rb
geocoder-1.2.8 lib/geocoder/results/nominatim.rb
geocoder-1.2.7 lib/geocoder/results/nominatim.rb