Sha256: c095aab4034e9450b758bac233644195fb97ccea9068f92c1a1eb4a31838f3ee

Contents?: true

Size: 932 Bytes

Versions: 19

Compression:

Stored size: 932 Bytes

Contents

require 'geocoder/results/base'

module Geocoder::Result
  class Esri < Base

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

    def city
      attributes['City']
    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

  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
geocoder-1.2.12 lib/geocoder/results/esri.rb
geocoder-1.2.11 lib/geocoder/results/esri.rb
geocoder-1.2.10 lib/geocoder/results/esri.rb
geocoder-1.2.9 lib/geocoder/results/esri.rb
geocoder-1.2.8 lib/geocoder/results/esri.rb
geocoder-1.2.7 lib/geocoder/results/esri.rb
geocoder-kb-1.2.6 lib/geocoder/results/esri.rb
geocoder-1.2.6 lib/geocoder/results/esri.rb
bw-geocoder-1.2.6 lib/geocoder/results/esri.rb
bw-geocoder-1.2.5 lib/geocoder/results/esri.rb
geocoder-1.2.5 lib/geocoder/results/esri.rb
geocoder-1.2.4 lib/geocoder/results/esri.rb
geocoder-1.2.3 lib/geocoder/results/esri.rb
geocoder-1.2.2 lib/geocoder/results/esri.rb
geocoder-1.2.1 lib/geocoder/results/esri.rb
geocoder-1.2.0 lib/geocoder/results/esri.rb
geocoder-1.1.9 lib/geocoder/results/esri.rb
geocoder-1.1.8 lib/geocoder/results/esri.rb
geocoder-1.1.7 lib/geocoder/results/esri.rb