Class: GoogleMapsGeocoder
- Inherits:
-
Object
- Object
- GoogleMapsGeocoder
- Defined in:
- lib/google_maps_geocoder/version.rb,
lib/google_maps_geocoder/google_maps_geocoder.rb
Overview
A simple PORO wrapper for geocoding with Google Maps.
Defined Under Namespace
Classes: GeocodingError
Constant Summary collapse
- VERSION =
'0.6.0'.freeze
- GOOGLE_ADDRESS_SEGMENTS =
i[ city country_long_name country_short_name county lat lng postal_code state_long_name state_short_name ].freeze
- GOOGLE_MAPS_API =
'https://maps.googleapis.com/maps/api/geocode/json'.freeze
- ALL_ADDRESS_SEGMENTS =
( GOOGLE_ADDRESS_SEGMENTS + i[formatted_address formatted_street_address] ).freeze
Instance Attribute Summary collapse
-
#formatted_address ⇒ String
readonly
Returns the complete formatted address with standardized abbreviations.
-
#formatted_street_address ⇒ String
readonly
Returns the formatted street address with standardized abbreviations.
Instance Method Summary collapse
-
#exact_match? ⇒ boolean
Returns true if the address Google returns is an exact match.
-
#initialize(address) ⇒ GoogleMapsGeocoder
constructor
Geocodes the specified address and wraps the results in a GoogleMapsGeocoder object.
-
#partial_match? ⇒ boolean
Returns true if the address Google returns isn’t an exact match.
Constructor Details
#initialize(address) ⇒ GoogleMapsGeocoder
Geocodes the specified address and wraps the results in a GoogleMapsGeocoder object.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/google_maps_geocoder/google_maps_geocoder.rb', line 51 def initialize(address) @json = address.is_a?(String) ? google_maps_response(address) : address status = @json && @json['status'] raise RuntimeError if status == 'OVER_QUERY_LIMIT' raise GeocodingError, @json if @json.blank? || status != 'OK' set_attributes_from_json Logger.new(STDERR).info('GoogleMapsGeocoder') do "Geocoded \"#{address}\" => \"#{formatted_address}\"" end end |
Instance Attribute Details
#formatted_address ⇒ String (readonly)
Returns the complete formatted address with standardized abbreviations.
31 32 33 |
# File 'lib/google_maps_geocoder/google_maps_geocoder.rb', line 31 def formatted_address @formatted_address end |
#formatted_street_address ⇒ String (readonly)
Returns the formatted street address with standardized abbreviations.
39 40 41 |
# File 'lib/google_maps_geocoder/google_maps_geocoder.rb', line 39 def formatted_street_address @formatted_street_address end |
Instance Method Details
#exact_match? ⇒ boolean
Returns true if the address Google returns is an exact match.
69 70 71 |
# File 'lib/google_maps_geocoder/google_maps_geocoder.rb', line 69 def exact_match? !partial_match? end |
#partial_match? ⇒ boolean
Returns true if the address Google returns isn’t an exact match.
79 80 81 |
# File 'lib/google_maps_geocoder/google_maps_geocoder.rb', line 79 def partial_match? @json['results'][0]['partial_match'] == true end |