Class: Geocoder::Result::GeocoderCa

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

Instance Attribute Summary

Attributes inherited from Base

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #latitude, #longitude

Constructor Details

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

Class Method Details

.response_attributesObject



46
47
48
49
50
# File 'lib/geocoder/results/geocoder_ca.rb', line 46

def self.response_attributes
  %w[latt longt inlatt inlongt betweenRoad1 betweenRoad2 distance
    stnumber staddress city prov postal
    NearRoad NearRoadDistance 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}"
end

#canadian_province_abbreviationsObject



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

def canadian_province_abbreviations
  %w[ON QC NS NB MB BC PE SK AB NL]
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
40
# File 'lib/geocoder/results/geocoder_ca.rb', line 36

def country_code
  prov = @data['prov']
  return nil if prov.nil? || prov == ""
  canadian_province_abbreviations.include?(@data['prov']) ? "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: province



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