Sha256: bd2d15f919c7f4c625b473dfcc79ff3c119c3a73c8e32b3dcb033473bf56de52

Contents?: true

Size: 1.95 KB

Versions: 34

Compression:

Stored size: 1.95 KB

Contents

require 'geocoder/lookups/base'

module Geocoder::Result
  class SmartyStreets < Base
    def coordinates
      %w(latitude longitude).map do |i|
        zipcode_endpoint? ? zipcodes.first[i] : metadata[i]
      end
    end

    def address
      [
        delivery_line_1,
        delivery_line_2,
        last_line
      ].select{ |i| i.to_s != "" }.join(" ")
    end

    def state
      zipcode_endpoint? ?
        city_states.first['state'] :
        components['state_abbreviation']
    end

    def state_code
      zipcode_endpoint? ?
        city_states.first['state_abbreviation'] :
        components['state_abbreviation']
    end

    def country
      # SmartyStreets returns results for USA only
      "United States"
    end

    def country_code
      # SmartyStreets returns results for USA only
      "US"
    end

    ## Extra methods not in base.rb ------------------------

    def street
      components['street_name']
    end

    def city
      zipcode_endpoint? ?
        city_states.first['city'] :
        components['city_name']
    end

    def zipcode
      zipcode_endpoint? ?
        zipcodes.first['zipcode'] :
        components['zipcode']
    end
    alias_method :postal_code, :zipcode

    def zip4
      components['plus4_code']
    end
    alias_method :postal_code_extended, :zip4

    def fips
      zipcode_endpoint? ?
        zipcodes.first['county_fips'] :
        metadata['county_fips']
    end

    def zipcode_endpoint?
      zipcodes.any?
    end

    [
      :delivery_line_1,
      :delivery_line_2,
      :last_line,
      :delivery_point_barcode,
      :addressee
    ].each do |m|
      define_method(m) do
        @data[m.to_s] || ''
      end
    end

    [
      :components,
      :metadata,
      :analysis
    ].each do |m|
      define_method(m) do
        @data[m.to_s] || {}
      end
    end

    [
      :city_states,
      :zipcodes
    ].each do |m|
      define_method(m) do
        @data[m.to_s] || []
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 5 rubygems

Version Path
geocoder-1.2.10 lib/geocoder/results/smarty_streets.rb
geocoder-1.2.9 lib/geocoder/results/smarty_streets.rb
geocoder-1.2.8 lib/geocoder/results/smarty_streets.rb
geocoder-1.2.7 lib/geocoder/results/smarty_streets.rb
geocoder-kb-1.2.6 lib/geocoder/results/smarty_streets.rb
geocoder-1.2.6 lib/geocoder/results/smarty_streets.rb
bw-geocoder-1.2.6 lib/geocoder/results/smarty_streets.rb
bw-geocoder-1.2.5 lib/geocoder/results/smarty_streets.rb
geocoder-1.2.5 lib/geocoder/results/smarty_streets.rb
geocoder-1.2.4 lib/geocoder/results/smarty_streets.rb
geocoder-1.2.3 lib/geocoder/results/smarty_streets.rb
geocoder-1.2.2 lib/geocoder/results/smarty_streets.rb
geocoder-1.2.1 lib/geocoder/results/smarty_streets.rb
geocoder-1.2.0 lib/geocoder/results/smarty_streets.rb