module Geoloco
Geoloco
is a multi-adpater geolocation gem, with error handling and test stubs
Constants
- Geometry
Geometry
data@attr [Float] lat latitude @attr [Float] lng longitude
- Location
- VERSION
Attributes
config[W]
default_adapter[W]
http[W]
Public Class Methods
config()
click to toggle source
# File lib/geoloco.rb, line 36 def config @config || {} end
default_adapter()
click to toggle source
# File lib/geoloco.rb, line 32 def default_adapter @default_adapter || :google end
geocode(query, adapter: default_adapter, **options)
click to toggle source
Geocodes a given query using the given adapter and options
@param query [String] the query to geocode @param adapter [String,Symbol] the adapter to use @returns [Array<Geocode::Location>] @raise [Geoloco::Error] if an error occurs @raise [Geoloco::UnknownAdapter] if an unknown adapter is given @raise [Geoloco::Forbidden] if the geocoder API returns a 403 error
# File lib/geoloco.rb, line 52 def geocode(query, adapter: default_adapter, **options) adapter_config = config.fetch(adapter, {}).merge(options) geocoder(adapter).geocode(query, **adapter_config) end
http()
click to toggle source
# File lib/geoloco.rb, line 40 def http @http || HTTParty end
Private Class Methods
geocoder(adapter)
click to toggle source
# File lib/geoloco.rb, line 59 def geocoder(adapter) camelized = adapter.to_s.split('_').map(&:capitalize).join Geoloco::Adapters.const_get(camelized) rescue NameError raise Geoloco::UnknownAdapter end