geocoder2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/.gitignore +5 -0
  2. data/.travis.yml +27 -0
  3. data/CHANGELOG.md +329 -0
  4. data/LICENSE +20 -0
  5. data/README.md +796 -0
  6. data/Rakefile +25 -0
  7. data/bin/geocode2 +5 -0
  8. data/examples/autoexpire_cache_dalli.rb +62 -0
  9. data/examples/autoexpire_cache_redis.rb +28 -0
  10. data/examples/cache_bypass.rb +48 -0
  11. data/gemfiles/Gemfile.mongoid-2.4.x +15 -0
  12. data/json?address=26+leonard+street%2C+Belmont&key=AIzaSyDoltU6YL8XeIQrSLFGk6ZfpKaWkPukwYQ&language=en +68 -0
  13. data/lib/generators/geocoder2/config/config_generator.rb +14 -0
  14. data/lib/generators/geocoder2/config/templates/initializer.rb +21 -0
  15. data/lib/geocoder2/cache.rb +89 -0
  16. data/lib/geocoder2/calculations.rb +389 -0
  17. data/lib/geocoder2/cli.rb +121 -0
  18. data/lib/geocoder2/configuration.rb +130 -0
  19. data/lib/geocoder2/configuration_hash.rb +11 -0
  20. data/lib/geocoder2/exceptions.rb +21 -0
  21. data/lib/geocoder2/lookup.rb +86 -0
  22. data/lib/geocoder2/lookups/baidu.rb +54 -0
  23. data/lib/geocoder2/lookups/base.rb +266 -0
  24. data/lib/geocoder2/lookups/bing.rb +47 -0
  25. data/lib/geocoder2/lookups/dstk.rb +20 -0
  26. data/lib/geocoder2/lookups/esri.rb +48 -0
  27. data/lib/geocoder2/lookups/freegeoip.rb +43 -0
  28. data/lib/geocoder2/lookups/geocoder_ca.rb +54 -0
  29. data/lib/geocoder2/lookups/geocoder_us.rb +39 -0
  30. data/lib/geocoder2/lookups/google.rb +69 -0
  31. data/lib/geocoder2/lookups/google_premier.rb +47 -0
  32. data/lib/geocoder2/lookups/mapquest.rb +59 -0
  33. data/lib/geocoder2/lookups/maxmind.rb +88 -0
  34. data/lib/geocoder2/lookups/nominatim.rb +44 -0
  35. data/lib/geocoder2/lookups/ovi.rb +62 -0
  36. data/lib/geocoder2/lookups/test.rb +44 -0
  37. data/lib/geocoder2/lookups/yahoo.rb +86 -0
  38. data/lib/geocoder2/lookups/yandex.rb +54 -0
  39. data/lib/geocoder2/models/active_record.rb +46 -0
  40. data/lib/geocoder2/models/base.rb +42 -0
  41. data/lib/geocoder2/models/mongo_base.rb +60 -0
  42. data/lib/geocoder2/models/mongo_mapper.rb +26 -0
  43. data/lib/geocoder2/models/mongoid.rb +32 -0
  44. data/lib/geocoder2/query.rb +107 -0
  45. data/lib/geocoder2/railtie.rb +26 -0
  46. data/lib/geocoder2/request.rb +23 -0
  47. data/lib/geocoder2/results/baidu.rb +79 -0
  48. data/lib/geocoder2/results/base.rb +67 -0
  49. data/lib/geocoder2/results/bing.rb +48 -0
  50. data/lib/geocoder2/results/dstk.rb +6 -0
  51. data/lib/geocoder2/results/esri.rb +51 -0
  52. data/lib/geocoder2/results/freegeoip.rb +45 -0
  53. data/lib/geocoder2/results/geocoder_ca.rb +60 -0
  54. data/lib/geocoder2/results/geocoder_us.rb +39 -0
  55. data/lib/geocoder2/results/google.rb +124 -0
  56. data/lib/geocoder2/results/google_premier.rb +6 -0
  57. data/lib/geocoder2/results/mapquest.rb +51 -0
  58. data/lib/geocoder2/results/maxmind.rb +135 -0
  59. data/lib/geocoder2/results/nominatim.rb +94 -0
  60. data/lib/geocoder2/results/ovi.rb +62 -0
  61. data/lib/geocoder2/results/test.rb +16 -0
  62. data/lib/geocoder2/results/yahoo.rb +55 -0
  63. data/lib/geocoder2/results/yandex.rb +80 -0
  64. data/lib/geocoder2/sql.rb +106 -0
  65. data/lib/geocoder2/stores/active_record.rb +272 -0
  66. data/lib/geocoder2/stores/base.rb +120 -0
  67. data/lib/geocoder2/stores/mongo_base.rb +89 -0
  68. data/lib/geocoder2/stores/mongo_mapper.rb +13 -0
  69. data/lib/geocoder2/stores/mongoid.rb +13 -0
  70. data/lib/geocoder2/version.rb +3 -0
  71. data/lib/geocoder2.rb +55 -0
  72. data/lib/hash_recursive_merge.rb +74 -0
  73. data/lib/oauth_util.rb +112 -0
  74. data/lib/tasks/geocoder2.rake +27 -0
  75. data/test/active_record_test.rb +15 -0
  76. data/test/cache_test.rb +35 -0
  77. data/test/calculations_test.rb +211 -0
  78. data/test/configuration_test.rb +78 -0
  79. data/test/custom_block_test.rb +32 -0
  80. data/test/error_handling_test.rb +43 -0
  81. data/test/fixtures/baidu_invalid_key +1 -0
  82. data/test/fixtures/baidu_no_results +1 -0
  83. data/test/fixtures/baidu_reverse +1 -0
  84. data/test/fixtures/baidu_shanghai_pearl_tower +12 -0
  85. data/test/fixtures/bing_invalid_key +1 -0
  86. data/test/fixtures/bing_madison_square_garden +40 -0
  87. data/test/fixtures/bing_no_results +16 -0
  88. data/test/fixtures/bing_reverse +42 -0
  89. data/test/fixtures/esri_madison_square_garden +59 -0
  90. data/test/fixtures/esri_no_results +8 -0
  91. data/test/fixtures/esri_reverse +21 -0
  92. data/test/fixtures/freegeoip_74_200_247_59 +12 -0
  93. data/test/fixtures/freegeoip_no_results +1 -0
  94. data/test/fixtures/geocoder_ca_madison_square_garden +1 -0
  95. data/test/fixtures/geocoder_ca_no_results +1 -0
  96. data/test/fixtures/geocoder_ca_reverse +34 -0
  97. data/test/fixtures/geocoder_us_madison_square_garden +1 -0
  98. data/test/fixtures/geocoder_us_no_results +1 -0
  99. data/test/fixtures/google_garbage +456 -0
  100. data/test/fixtures/google_madison_square_garden +57 -0
  101. data/test/fixtures/google_no_city_data +44 -0
  102. data/test/fixtures/google_no_locality +51 -0
  103. data/test/fixtures/google_no_results +4 -0
  104. data/test/fixtures/google_over_limit +4 -0
  105. data/test/fixtures/mapquest_error +16 -0
  106. data/test/fixtures/mapquest_invalid_api_key +16 -0
  107. data/test/fixtures/mapquest_invalid_request +16 -0
  108. data/test/fixtures/mapquest_madison_square_garden +52 -0
  109. data/test/fixtures/mapquest_no_results +16 -0
  110. data/test/fixtures/maxmind_24_24_24_21 +1 -0
  111. data/test/fixtures/maxmind_24_24_24_22 +1 -0
  112. data/test/fixtures/maxmind_24_24_24_23 +1 -0
  113. data/test/fixtures/maxmind_24_24_24_24 +1 -0
  114. data/test/fixtures/maxmind_74_200_247_59 +1 -0
  115. data/test/fixtures/maxmind_invalid_key +1 -0
  116. data/test/fixtures/maxmind_no_results +1 -0
  117. data/test/fixtures/nominatim_madison_square_garden +150 -0
  118. data/test/fixtures/nominatim_no_results +1 -0
  119. data/test/fixtures/ovi_madison_square_garden +72 -0
  120. data/test/fixtures/ovi_no_results +8 -0
  121. data/test/fixtures/yahoo_error +1 -0
  122. data/test/fixtures/yahoo_invalid_key +2 -0
  123. data/test/fixtures/yahoo_madison_square_garden +52 -0
  124. data/test/fixtures/yahoo_no_results +10 -0
  125. data/test/fixtures/yahoo_over_limit +2 -0
  126. data/test/fixtures/yandex_invalid_key +1 -0
  127. data/test/fixtures/yandex_kremlin +48 -0
  128. data/test/fixtures/yandex_no_city_and_town +112 -0
  129. data/test/fixtures/yandex_no_results +16 -0
  130. data/test/geocoder_test.rb +59 -0
  131. data/test/https_test.rb +16 -0
  132. data/test/integration/smoke_test.rb +26 -0
  133. data/test/lookup_test.rb +117 -0
  134. data/test/method_aliases_test.rb +25 -0
  135. data/test/mongoid_test.rb +46 -0
  136. data/test/mongoid_test_helper.rb +43 -0
  137. data/test/near_test.rb +61 -0
  138. data/test/oauth_util_test.rb +30 -0
  139. data/test/proxy_test.rb +36 -0
  140. data/test/query_test.rb +52 -0
  141. data/test/request_test.rb +29 -0
  142. data/test/result_test.rb +42 -0
  143. data/test/services_test.rb +393 -0
  144. data/test/test_helper.rb +289 -0
  145. data/test/test_mode_test.rb +59 -0
  146. metadata +213 -0
@@ -0,0 +1,124 @@
1
+ require 'geocoder2/results/base'
2
+
3
+ module Geocoder2::Result
4
+ class Google < Base
5
+
6
+ def coordinates
7
+ ['lat', 'lng'].map{ |i| geometry['location'][i] }
8
+ end
9
+
10
+ def address(format = :full)
11
+ formatted_address
12
+ end
13
+
14
+ def neighborhood
15
+ if neighborhood = address_components_of_type(:neighborhood).first
16
+ neighborhood['long_name']
17
+ end
18
+ end
19
+
20
+ def city
21
+ fields = [:locality, :sublocality,
22
+ :administrative_area_level_3,
23
+ :administrative_area_level_2]
24
+ fields.each do |f|
25
+ if entity = address_components_of_type(f).first
26
+ return entity['long_name']
27
+ end
28
+ end
29
+ return nil # no appropriate components found
30
+ end
31
+
32
+ def state
33
+ if state = address_components_of_type(:administrative_area_level_1).first
34
+ state['long_name']
35
+ end
36
+ end
37
+
38
+ def state_code
39
+ if state = address_components_of_type(:administrative_area_level_1).first
40
+ state['short_name']
41
+ end
42
+ end
43
+
44
+ def sub_state
45
+ if state = address_components_of_type(:administrative_area_level_2).first
46
+ state['long_name']
47
+ end
48
+ end
49
+
50
+ def sub_state_code
51
+ if state = address_components_of_type(:administrative_area_level_2).first
52
+ state['short_name']
53
+ end
54
+ end
55
+
56
+ def country
57
+ if country = address_components_of_type(:country).first
58
+ country['long_name']
59
+ end
60
+ end
61
+
62
+ def country_code
63
+ if country = address_components_of_type(:country).first
64
+ country['short_name']
65
+ end
66
+ end
67
+
68
+ def postal_code
69
+ if postal = address_components_of_type(:postal_code).first
70
+ postal['long_name']
71
+ end
72
+ end
73
+
74
+ def route
75
+ if route = address_components_of_type(:route).first
76
+ route['long_name']
77
+ end
78
+ end
79
+
80
+ def street_number
81
+ if street_number = address_components_of_type(:street_number).first
82
+ street_number['long_name']
83
+ end
84
+ end
85
+
86
+ def street_address
87
+ [street_number, route].compact.join(' ')
88
+ end
89
+
90
+ def types
91
+ @data['types']
92
+ end
93
+
94
+ def formatted_address
95
+ @data['formatted_address']
96
+ end
97
+
98
+ def address_components
99
+ @data['address_components']
100
+ end
101
+
102
+ ##
103
+ # Get address components of a given type. Valid types are defined in
104
+ # Google's Geocoding API documentation and include (among others):
105
+ #
106
+ # :street_number
107
+ # :locality
108
+ # :neighborhood
109
+ # :route
110
+ # :postal_code
111
+ #
112
+ def address_components_of_type(type)
113
+ address_components.select{ |c| c['types'].include?(type.to_s) }
114
+ end
115
+
116
+ def geometry
117
+ @data['geometry']
118
+ end
119
+
120
+ def precision
121
+ geometry['location_type'] if geometry
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,6 @@
1
+ require 'geocoder2/results/google'
2
+
3
+ module Geocoder2::Result
4
+ class GooglePremier < Google
5
+ end
6
+ end
@@ -0,0 +1,51 @@
1
+ require 'geocoder2/results/base'
2
+
3
+ module Geocoder2::Result
4
+ class Mapquest < Base
5
+ def latitude
6
+ @data["latLng"]["lat"]
7
+ end
8
+
9
+ def longitude
10
+ @data["latLng"]["lng"]
11
+ end
12
+
13
+ def coordinates
14
+ [latitude, longitude]
15
+ end
16
+
17
+ def city
18
+ @data['adminArea5']
19
+ end
20
+
21
+ def street
22
+ @data['street']
23
+ end
24
+
25
+ def state
26
+ @data['adminArea3']
27
+ end
28
+
29
+ alias_method :state_code, :state
30
+
31
+ #FIXME: these might not be right, unclear with MQ documentation
32
+ alias_method :province, :state
33
+ alias_method :province_code, :state
34
+
35
+ def postal_code
36
+ @data['postalCode'].to_s
37
+ end
38
+
39
+ def country
40
+ @data['adminArea1']
41
+ end
42
+
43
+ def country_code
44
+ country
45
+ end
46
+
47
+ def address
48
+ [street, city, state, postal_code, country].reject{|s| s.length == 0 }.join(", ")
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,135 @@
1
+ require 'geocoder2/results/base'
2
+
3
+ module Geocoder2::Result
4
+ class Maxmind < Base
5
+
6
+ ##
7
+ # Hash mapping service names to names of returned fields.
8
+ #
9
+ def self.field_names
10
+ {
11
+ :country => [
12
+ :country_code,
13
+ :error
14
+ ],
15
+
16
+ :city => [
17
+ :country_code,
18
+ :region_code,
19
+ :city_name,
20
+ :latitude,
21
+ :longitude,
22
+ :error
23
+ ],
24
+
25
+ :city_isp_org => [
26
+ :country_code,
27
+ :region_code,
28
+ :city_name,
29
+ :postal_code,
30
+ :latitude,
31
+ :longitude,
32
+ :metro_code,
33
+ :area_code,
34
+ :isp_name,
35
+ :organization_name,
36
+ :error
37
+ ],
38
+
39
+ :omni => [
40
+ :country_code,
41
+ :country_name,
42
+ :region_code,
43
+ :region_name,
44
+ :city_name,
45
+ :latitude,
46
+ :longitude,
47
+ :metro_code,
48
+ :area_code,
49
+ :time_zone,
50
+ :continent_code,
51
+ :postal_code,
52
+ :isp_name,
53
+ :organization_name,
54
+ :domain,
55
+ :as_number,
56
+ :netspeed,
57
+ :user_type,
58
+ :accuracy_radius,
59
+ :country_confidence_factor,
60
+ :city_confidence_factor,
61
+ :region_confidence_factor,
62
+ :postal_confidence_factor,
63
+ :error
64
+ ]
65
+ }
66
+ end
67
+
68
+ ##
69
+ # Name of the MaxMind service being used.
70
+ #
71
+ def service_name
72
+ # it would be much better to infer this from the length of the @data
73
+ # array, but MaxMind seems to send inconsistent and wide-ranging response
74
+ # lengths (see https://github.com/alexreisner/geocoder2/issues/396)
75
+ Geocoder2.config.maxmind[:service]
76
+ end
77
+
78
+ def field_names
79
+ self.class.field_names[service_name]
80
+ end
81
+
82
+ def data_hash
83
+ @data_hash ||= Hash[*field_names.zip(@data).flatten]
84
+ end
85
+
86
+ def coordinates
87
+ [data_hash[:latitude].to_f, data_hash[:longitude].to_f]
88
+ end
89
+
90
+ def address(format = :full)
91
+ s = state_code.to_s == "" ? "" : ", #{state_code}"
92
+ "#{city}#{s} #{postal_code}, #{country_code}".sub(/^[ ,]*/, "")
93
+ end
94
+
95
+ def city
96
+ data_hash[:city_name]
97
+ end
98
+
99
+ def state # not given by MaxMind
100
+ data_hash[:region_name] || data_hash[:region_code]
101
+ end
102
+
103
+ def state_code
104
+ data_hash[:region_code]
105
+ end
106
+
107
+ def country #not given by MaxMind
108
+ data_hash[:country_name] || data_hash[:country_code]
109
+ end
110
+
111
+ def country_code
112
+ data_hash[:country_code]
113
+ end
114
+
115
+ def postal_code
116
+ data_hash[:postal_code]
117
+ end
118
+
119
+ def method_missing(method, *args, &block)
120
+ if field_names.include?(method)
121
+ data_hash[method]
122
+ else
123
+ super
124
+ end
125
+ end
126
+
127
+ def respond_to?(method)
128
+ if field_names.include?(method)
129
+ true
130
+ else
131
+ super
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,94 @@
1
+ require 'geocoder2/results/base'
2
+
3
+ module Geocoder2::Result
4
+ class Nominatim < Base
5
+
6
+ def poi
7
+ %w[stadium bus_stop tram_stop].each do |key|
8
+ return @data['address'][key] if @data['address'].key?(key)
9
+ end
10
+ return nil
11
+ end
12
+
13
+ def house_number
14
+ @data['address']['house_number']
15
+ end
16
+
17
+ def address
18
+ @data['display_name']
19
+ end
20
+
21
+ def street
22
+ %w[road pedestrian highway].each do |key|
23
+ return @data['address'][key] if @data['address'].key?(key)
24
+ end
25
+ return nil
26
+ end
27
+
28
+ def city
29
+ %w[city town village hamlet].each do |key|
30
+ return @data['address'][key] if @data['address'].key?(key)
31
+ end
32
+ return nil
33
+ end
34
+
35
+ def village
36
+ @data['address']['village']
37
+ end
38
+
39
+ def town
40
+ @data['address']['town']
41
+ end
42
+
43
+ def state
44
+ @data['address']['state']
45
+ end
46
+
47
+ alias_method :state_code, :state
48
+
49
+ def postal_code
50
+ @data['address']['postcode']
51
+ end
52
+
53
+ def county
54
+ @data['address']['county']
55
+ end
56
+
57
+ def country
58
+ @data['address']['country']
59
+ end
60
+
61
+ def country_code
62
+ @data['address']['country_code']
63
+ end
64
+
65
+ def suburb
66
+ @data['address']['suburb']
67
+ end
68
+
69
+ def coordinates
70
+ [@data['lat'].to_f, @data['lon'].to_f]
71
+ end
72
+
73
+ def place_class
74
+ @data['class']
75
+ end
76
+
77
+ def place_type
78
+ @data['type']
79
+ end
80
+
81
+ def self.response_attributes
82
+ %w[place_id osm_type osm_id boundingbox license
83
+ polygonpoints display_name class type stadium]
84
+ end
85
+
86
+ response_attributes.each do |a|
87
+ unless method_defined?(a)
88
+ define_method a do
89
+ @data[a]
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,62 @@
1
+ require 'geocoder2/results/base'
2
+
3
+ module Geocoder2::Result
4
+ class Ovi < Base
5
+
6
+ ##
7
+ # A string in the given format.
8
+ #
9
+ def address(format = :full)
10
+ address_data['Label']
11
+ end
12
+
13
+ ##
14
+ # A two-element array: [lat, lon].
15
+ #
16
+ def coordinates
17
+ fail unless d = @data['Location']['DisplayPosition']
18
+ [d['Latitude'].to_f, d['Longitude'].to_f]
19
+ end
20
+
21
+ def state
22
+ address_data['County']
23
+ end
24
+
25
+ def province
26
+ address_data['County']
27
+ end
28
+
29
+ def postal_code
30
+ address_data['PostalCode']
31
+ end
32
+
33
+ def city
34
+ address_data['City']
35
+ end
36
+
37
+ def state_code
38
+ address_data['State']
39
+ end
40
+
41
+ def province_code
42
+ address_data['State']
43
+ end
44
+
45
+ def country
46
+ fail unless d = address_data['AdditionalData']
47
+ if v = d.find{|ad| ad['key']=='CountryName'}
48
+ return v['value']
49
+ end
50
+ end
51
+
52
+ def country_code
53
+ address_data['Country']
54
+ end
55
+
56
+ private # ----------------------------------------------------------------
57
+
58
+ def address_data
59
+ @data['Location']['Address'] || fail
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,16 @@
1
+ require 'geocoder2/results/base'
2
+
3
+ module Geocoder2
4
+ module Result
5
+ class Test < Base
6
+
7
+ %w[latitude longitude city state state_code province
8
+ province_code postal_code country country_code address
9
+ street_address street_number route].each do |attr|
10
+ define_method(attr) do
11
+ @data[attr.to_s] || @data[attr.to_sym]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,55 @@
1
+ require 'geocoder2/results/base'
2
+
3
+ module Geocoder2::Result
4
+ class Yahoo < Base
5
+
6
+ def address(format = :full)
7
+ (1..4).to_a.map{ |i| @data["line#{i}"] }.reject{ |i| i.nil? or i == "" }.join(", ")
8
+ end
9
+
10
+ def city
11
+ @data['city']
12
+ end
13
+
14
+ def state
15
+ @data['state']
16
+ end
17
+
18
+ def state_code
19
+ @data['statecode']
20
+ end
21
+
22
+ def country
23
+ @data['country']
24
+ end
25
+
26
+ def country_code
27
+ @data['countrycode']
28
+ end
29
+
30
+ def postal_code
31
+ @data['postal']
32
+ end
33
+
34
+ def address_hash
35
+ @data['hash']
36
+ end
37
+
38
+ def self.response_attributes
39
+ %w[quality offsetlat offsetlon radius boundingbox name
40
+ line1 line2 line3 line4 cross house street xstreet unittype unit
41
+ city state statecode country countrycode postal
42
+ neighborhood county countycode
43
+ level0 level1 level2 level3 level4 level0code level1code level2code
44
+ timezone areacode uzip hash woeid woetype]
45
+ end
46
+
47
+ response_attributes.each do |a|
48
+ unless method_defined?(a)
49
+ define_method a do
50
+ @data[a]
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,80 @@
1
+ require 'geocoder2/results/base'
2
+
3
+ module Geocoder2::Result
4
+ class Yandex < Base
5
+
6
+ def coordinates
7
+ @data['GeoObject']['Point']['pos'].split(' ').reverse.map(&:to_f)
8
+ end
9
+
10
+ def address(format = :full)
11
+ @data['GeoObject']['metaDataProperty']['Geocoder2MetaData']['text']
12
+ end
13
+
14
+ def city
15
+ if state.empty? and address_details.has_key? 'Locality'
16
+ address_details['Locality']['LocalityName']
17
+ elsif sub_state.empty?
18
+ address_details['AdministrativeArea']['Locality']['LocalityName']
19
+ elsif not sub_state_city.empty?
20
+ sub_state_city
21
+ else
22
+ ""
23
+ end
24
+ end
25
+
26
+ def country
27
+ address_details['CountryName']
28
+ end
29
+
30
+ def country_code
31
+ address_details['CountryNameCode']
32
+ end
33
+
34
+ def state
35
+ if address_details['AdministrativeArea']
36
+ address_details['AdministrativeArea']['AdministrativeAreaName']
37
+ else
38
+ ""
39
+ end
40
+ end
41
+
42
+ def sub_state
43
+ if !state.empty? and address_details['AdministrativeArea']['SubAdministrativeArea']
44
+ address_details['AdministrativeArea']['SubAdministrativeArea']['SubAdministrativeAreaName']
45
+ else
46
+ ""
47
+ end
48
+ end
49
+
50
+ def state_code
51
+ ""
52
+ end
53
+
54
+ def postal_code
55
+ ""
56
+ end
57
+
58
+ def premise_name
59
+ address_details['Locality']['Premise']['PremiseName']
60
+ end
61
+
62
+ def precision
63
+ @data['GeoObject']['metaDataProperty']['Geocoder2MetaData']['precision']
64
+ end
65
+
66
+ private # ----------------------------------------------------------------
67
+
68
+ def address_details
69
+ @data['GeoObject']['metaDataProperty']['Geocoder2MetaData']['AddressDetails']['Country']
70
+ end
71
+
72
+ def sub_state_city
73
+ if sub_state && sub_state["Locality"]
74
+ sub_state['Locality']['LocalityName']
75
+ else
76
+ ""
77
+ end
78
+ end
79
+ end
80
+ end