Sha256: 754cd4c5fe24fd639c0d9e5eefc130bd5b25132fd584bfd76d5359683191f92b

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

require 'geocoder/results/base'

module Geocoder::Result
  class Geocodio < Base
    def number
      address_components["number"]
    end

    def street
      address_components["street"]
    end

    def suffix
      address_components["suffix"]
    end

    def state
      address_components["state"]
    end
    alias_method :state_code, :state

    def zip
      address_components["zip"]
    end
    alias_method :postal_code, :zip

    def country
      "United States" # Geocodio only supports the US
    end

    def country_code
      "US" # Geocodio only supports the US
    end

    def city
      address_components["city"]
    end

    def postdirectional
      address_components["postdirectional"]
    end

    def location
      @data['location']
    end

    def coordinates
      ['lat', 'lng'].map{ |i| location[i] } if location
    end

    def accuracy
      @data['accuracy'].to_f if @data.key?('accuracy')
    end

    def formatted_address(format = :full)
      @data['formatted_address']
    end
    alias_method :address, :formatted_address

    private

    def address_components
      @data['address_components'] || {}
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
geocoder-1.2.3 lib/geocoder/results/geocodio.rb
geocoder-1.2.2 lib/geocoder/results/geocodio.rb
geocoder-1.2.1 lib/geocoder/results/geocodio.rb
geocoder-1.2.0 lib/geocoder/results/geocodio.rb