class Geocoder::Result::Base

Attributes

cache_hit[RW]

true if result came from cache, false if from request to geocoding service; nil if cache is not configured

data[RW]

data (hash) fetched from geocoding service

Public Class Methods

new(data) click to toggle source

Takes a hash of data from a parsed geocoding service response.

# File lib/geocoder/results/base.rb, line 15
def initialize(data)
  @data = data
  @cache_hit = nil
end

Public Instance Methods

address(format = :full) click to toggle source

A string in the given format.

This default implementation dumbly follows the United States address format and will return incorrect results for most countries. Some APIs return properly formatted addresses and those should be funneled through this method.

# File lib/geocoder/results/base.rb, line 28
def address(format = :full)
  if state_code.to_s != ""
    s = ", #{state_code}"
  elsif state.to_s != ""
    s = ", #{state}"
  else
    s = ""
  end
  "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '')
end
coordinates() click to toggle source

A two-element array: [lat, lon].

# File lib/geocoder/results/base.rb, line 42
def coordinates
  [@data['latitude'].to_f, @data['longitude'].to_f]
end
country() click to toggle source
# File lib/geocoder/results/base.rb, line 70
def country
  fail
end
country_code() click to toggle source
# File lib/geocoder/results/base.rb, line 74
def country_code
  fail
end
latitude() click to toggle source
# File lib/geocoder/results/base.rb, line 46
def latitude
  coordinates[0]
end
longitude() click to toggle source
# File lib/geocoder/results/base.rb, line 50
def longitude
  coordinates[1]
end
province() click to toggle source
# File lib/geocoder/results/base.rb, line 58
def province
  state
end
province_code() click to toggle source
# File lib/geocoder/results/base.rb, line 66
def province_code
  state_code
end
state() click to toggle source
# File lib/geocoder/results/base.rb, line 54
def state
  fail
end
state_code() click to toggle source
# File lib/geocoder/results/base.rb, line 62
def state_code
  fail
end