Sha256: a4c01286d2013ad72b8569a5dbaefcead8a101a6b25492fd4f72621060ab482c

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

require 'geocoder/results/base'

module Geocoder::Result
  class Esri < Base

    def address
      address = reverse_geocode? ? 'Address' : 'Match_addr'
      attributes[address]
    end

    def city
      if !reverse_geocode? && is_city?
        attributes['PlaceName']
      else
        attributes['City']
      end
    end

    def state_code
      attributes['Region']
    end

    alias_method :state, :state_code

    def country
      country = reverse_geocode? ? "CountryCode" : "Country"
      attributes[country]
    end

    alias_method :country_code, :country

    def postal_code
      attributes['Postal']
    end

    def coordinates
      [geometry["y"], geometry["x"]]
    end

    private

    def attributes
      reverse_geocode? ? @data['address'] : @data['locations'].first['feature']['attributes']
    end

    def geometry
      reverse_geocode? ? @data["location"] : @data['locations'].first['feature']["geometry"]
    end

    def reverse_geocode?
      @data['locations'].nil?
    end

    def is_city?
      ['City', 'State Capital', 'National Capital'].include?(attributes['Type'])
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geocoder-1.2.14 lib/geocoder/results/esri.rb
geocoder-1.2.13 lib/geocoder/results/esri.rb