Class: Geocoder::Result::GeocoderCa

Inherits:
Base
  • Object
show all
Defined in:
lib/geocoder/results/geocoder_ca.rb

Instance Attribute Summary

Attributes inherited from Base

#cache_hit, #data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #latitude, #longitude, #province, #province_code

Constructor Details

This class inherits a constructor from Geocoder::Result::Base

Class Method Details

.response_attributesObject


41
42
43
44
45
# File 'lib/geocoder/results/geocoder_ca.rb', line 41

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

Instance Method Details

#address(format = :full) ⇒ Object


10
11
12
# File 'lib/geocoder/results/geocoder_ca.rb', line 10

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

#cityObject


18
19
20
# File 'lib/geocoder/results/geocoder_ca.rb', line 18

def city
  @data['city']
end

#coordinatesObject


6
7
8
# File 'lib/geocoder/results/geocoder_ca.rb', line 6

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

#countryObject


32
33
34
# File 'lib/geocoder/results/geocoder_ca.rb', line 32

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

#country_codeObject


36
37
38
39
# File 'lib/geocoder/results/geocoder_ca.rb', line 36

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

#postal_codeObject


28
29
30
# File 'lib/geocoder/results/geocoder_ca.rb', line 28

def postal_code
  @data['postal']
end

#stateObject Also known as: state_code


22
23
24
# File 'lib/geocoder/results/geocoder_ca.rb', line 22

def state
  @data['prov']
end

#street_addressObject


14
15
16
# File 'lib/geocoder/results/geocoder_ca.rb', line 14

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