Sha256: e95498975efc64034c1f8c5795ede3c0d5db00413596a1fa1013e10dd52cf2eb

Contents?: true

Size: 1.41 KB

Versions: 23

Compression:

Stored size: 1.41 KB

Contents

require 'geocoder/results/base'

module Geocoder::Result
  class GeocoderCa < Base

    def coordinates
      [@data['latt'].to_f, @data['longt'].to_f]
    end

    def address(format = :full)
      "#{street_address}, #{city}, #{state} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
    end

    def street_address
      "#{@data['stnumber']} #{@data['staddress']}"
    end

    def city
      @data['city'] or (@data['standard'] and @data['standard']['city']) or ""
    end

    def state
      @data['prov'] or (@data['standard'] and @data['standard']['prov']) or ""
    end

    alias_method :state_code, :state

    def postal_code
      @data['postal'] or (@data['standard'] and @data['standard']['postal']) or ""
    end

    def country
      country_code == 'CA' ? 'Canada' : 'United States'
    end

    def country_code
      return nil if state.nil? || state == ""
      canadian_province_abbreviations.include?(state) ? "CA" : "US"
    end

    def self.response_attributes
      %w[latt longt inlatt inlongt distance stnumber staddress prov
        NearRoad NearRoadDistance betweenRoad1 betweenRoad2
        intersection major_intersection]
    end

    response_attributes.each do |a|
      define_method a do
        @data[a]
      end
    end


    private # ----------------------------------------------------------------

    def canadian_province_abbreviations
      %w[ON QC NS NB MB BC PE SK AB NL]
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
geocoder-1.8.3 lib/geocoder/results/geocoder_ca.rb
geocoder-1.8.2 lib/geocoder/results/geocoder_ca.rb
geocoder-1.8.1 lib/geocoder/results/geocoder_ca.rb
geocoder-1.8.0 lib/geocoder/results/geocoder_ca.rb
geocoder-1.7.5 lib/geocoder/results/geocoder_ca.rb
geocoder-1.7.4 lib/geocoder/results/geocoder_ca.rb
geocoder-1.7.3 lib/geocoder/results/geocoder_ca.rb
geocoder-1.7.2 lib/geocoder/results/geocoder_ca.rb
geocoder-1.7.1 lib/geocoder/results/geocoder_ca.rb
geocoder-1.7.0 lib/geocoder/results/geocoder_ca.rb
geocoder-1.6.7 lib/geocoder/results/geocoder_ca.rb
geocoder-1.6.6 lib/geocoder/results/geocoder_ca.rb
geocoder-1.6.5 lib/geocoder/results/geocoder_ca.rb
geocoder-1.6.4 lib/geocoder/results/geocoder_ca.rb
geocoder-1.6.3 lib/geocoder/results/geocoder_ca.rb
geocoder-1.6.2 lib/geocoder/results/geocoder_ca.rb
geocoder-1.6.1 lib/geocoder/results/geocoder_ca.rb
geocoder-1.6.0 lib/geocoder/results/geocoder_ca.rb
geocoder-1.5.2 lib/geocoder/results/geocoder_ca.rb
really-broken-geocoder-2.0.0 lib/geocoder/results/geocoder_ca.rb