Class: Geocoder::Result::Base
- Inherits:
-
Object
- Object
- Geocoder::Result::Base
show all
- Defined in:
- lib/geocoder/results/base.rb
Direct Known Subclasses
AbstractApi, Amap, AmazonLocationService, Azure, Baidu, BaiduIp, BanDataGouvFr, Bing, DbIpCom, Esri, Freegeoip, Geoapify, GeocoderCa, Geocodio, Geoip2, GeoportailLu, Google, Here, Ip2location, Ip2locationIo, Ip2locationLite, IpapiCom, Ipbase, IpdataCo, Ipgeolocation, IpinfoIo, Ipqualityscore, Ipregistry, Ipstack, Latlon, Mapbox, Mapquest, Maxmind, MaxmindLocal, MelissaStreet, NationaalGeoregisterNl, Nominatim, Opencagedata, Osmnames, PcMiler, PdokNl, Pelias, Photon, Pointpin, PostcodeAnywhereUk, PostcodesIo, SmartyStreets, Telize, Tencent, Test, Twogis, UkOrdnanceSurveyNames, Yandex
Instance Attribute Summary collapse
-
#cache_hit ⇒ Object
true if result came from cache, false if from request to geocoding service; nil if cache is not configured.
-
#data ⇒ Object
data (hash) fetched from geocoding service.
Instance Method Summary
collapse
Constructor Details
#initialize(data) ⇒ Base
Takes a hash of data from a parsed geocoding service response.
15
16
17
18
|
# File 'lib/geocoder/results/base.rb', line 15
def initialize(data)
@data = data
@cache_hit = nil
end
|
Instance Attribute Details
#cache_hit ⇒ Object
true if result came from cache, false if from request to geocoding service; nil if cache is not configured
10
11
12
|
# File 'lib/geocoder/results/base.rb', line 10
def cache_hit
@cache_hit
end
|
#data ⇒ Object
data (hash) fetched from geocoding service
6
7
8
|
# File 'lib/geocoder/results/base.rb', line 6
def data
@data
end
|
Instance Method Details
#address(format = :full) ⇒ Object
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.
28
29
30
31
32
33
34
35
36
37
|
# 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 ⇒ Object
A two-element array: [lat, lon].
42
43
44
|
# File 'lib/geocoder/results/base.rb', line 42
def coordinates
[@data['latitude'].to_f, @data['longitude'].to_f]
end
|
#country ⇒ Object
70
71
72
|
# File 'lib/geocoder/results/base.rb', line 70
def country
fail
end
|
#country_code ⇒ Object
74
75
76
|
# File 'lib/geocoder/results/base.rb', line 74
def country_code
fail
end
|
#latitude ⇒ Object
46
47
48
|
# File 'lib/geocoder/results/base.rb', line 46
def latitude
coordinates[0]
end
|
#longitude ⇒ Object
50
51
52
|
# File 'lib/geocoder/results/base.rb', line 50
def longitude
coordinates[1]
end
|
#province ⇒ Object
58
59
60
|
# File 'lib/geocoder/results/base.rb', line 58
def province
state
end
|
#province_code ⇒ Object
66
67
68
|
# File 'lib/geocoder/results/base.rb', line 66
def province_code
state_code
end
|
#state ⇒ Object
54
55
56
|
# File 'lib/geocoder/results/base.rb', line 54
def state
fail
end
|
#state_code ⇒ Object
62
63
64
|
# File 'lib/geocoder/results/base.rb', line 62
def state_code
fail
end
|