Class: GoogleMapsJuice::Geocoding::Response

Inherits:
Endpoint::Response show all
Defined in:
lib/google_maps_juice/geocoding/response.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Endpoint::Response

#error?, #error_message, #limit_error?, #results, #status, #zero_results?

Class Method Details

.precisionsObject



7
8
9
10
# File 'lib/google_maps_juice/geocoding/response.rb', line 7

def precisions
  %w( street_number route postal_code locality administrative_area_level_1
      administrative_area_level_2 administrative_area_level_3 country )
end

Instance Method Details

#address_componentsObject



33
34
35
# File 'lib/google_maps_juice/geocoding/response.rb', line 33

def address_components
  result['address_components']
end

#latitudeObject



13
14
15
# File 'lib/google_maps_juice/geocoding/response.rb', line 13

def latitude
  location['lat']
end

#locationObject



21
22
23
# File 'lib/google_maps_juice/geocoding/response.rb', line 21

def location
  result.dig('geometry', 'location')
end

#longitudeObject



17
18
19
# File 'lib/google_maps_juice/geocoding/response.rb', line 17

def longitude
  location['lng']
end

#partial_match?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/google_maps_juice/geocoding/response.rb', line 25

def partial_match?
  result['partial_match'] == true
end

#precisionObject



37
38
39
40
41
42
43
# File 'lib/google_maps_juice/geocoding/response.rb', line 37

def precision
  self.class.precisions.find do |type|
    address_components.any? do |comp|
      comp['types'].include?(type)
    end
  end
end

#resultObject



29
30
31
# File 'lib/google_maps_juice/geocoding/response.rb', line 29

def result
  results.first
end