Class: GmapsGeocoding::Config
- Inherits:
-
Object
- Object
- GmapsGeocoding::Config
- Defined in:
- lib/gmaps_geocoding/config.rb
Overview
Configuration class for GmapsGeocoding API.
Constant Summary collapse
- VALID_KEYS =
Configuration valid keys
[:url, :output, :address, :latlng, :components, :sensor, :bounds, :language, :region].freeze
- DEFAULT_CONFIG =
Default configuration values
{ url: 'https://maps.googleapis.com/maps/api/geocode', output: 'json', sensor: 'false' }.freeze
Instance Method Summary collapse
-
#address ⇒ String
The address that you want to geocode.
-
#bounds ⇒ String
The bounding box of the viewport within which to bias geocode results more prominently.
-
#components ⇒ String
A component filter for which you wish to obtain a geocode.
-
#initialize(opts = {}) ⇒ Config
constructor
A new instance of Config.
-
#json_format? ⇒ true, false
Check if the output format of the query is set to json.
-
#language ⇒ String
The language in which to return results.
-
#latlng ⇒ String
The textual latitude/longitude value for which you wish to obtain the closest, human-readable address.
-
#output ⇒ String
Output format of the Google Maps Geocoding Service.
-
#region ⇒ String
The region code, specified as a ccTLD (“top-level domain”) two-character value.
-
#sensor ⇒ String
Indicates whether or not the geocoding request comes from a device with a location sensor.
-
#url ⇒ String
URL of the Google Maps Geocoding Service.
-
#valid? ⇒ true, false
Check if the configuration object is valid.
-
#xml_format? ⇒ true, false
Check if the output format of the query is set to xml.
Constructor Details
#initialize(opts = {}) ⇒ Config
Returns a new instance of Config.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gmaps_geocoding/config.rb', line 15 def initialize(opts = {}) @options = {} @options.merge!(DEFAULT_CONFIG) opts.each do |k, _| next unless VALID_KEYS.include?(k) val = if k.eql?(:url) opts.delete(k) else ENV["GOOGLE_MAPS_GEOCODING_#{k.to_s.upcase}"] || opts.delete(k) end @options[k] = val if val end end |
Instance Method Details
#address ⇒ String
The address that you want to geocode
46 47 48 |
# File 'lib/gmaps_geocoding/config.rb', line 46 def address @options[:address] end |
#bounds ⇒ String
The bounding box of the viewport within which to bias geocode results more prominently
https://developers.google.com/maps/documentation/geocoding/#Viewports
79 80 81 |
# File 'lib/gmaps_geocoding/config.rb', line 79 def bounds @options[:bounds] end |
#components ⇒ String
A component filter for which you wish to obtain a geocode
https://developers.google.com/maps/documentation/geocoding/#ComponentFiltering
64 65 66 |
# File 'lib/gmaps_geocoding/config.rb', line 64 def components @options[:components] end |
#json_format? ⇒ true, false
Check if the output format of the query is set to json
108 109 110 |
# File 'lib/gmaps_geocoding/config.rb', line 108 def json_format? 'json'.eql?(output) end |
#language ⇒ String
The language in which to return results
86 87 88 |
# File 'lib/gmaps_geocoding/config.rb', line 86 def language @options[:language] end |
#latlng ⇒ String
The textual latitude/longitude value for which you wish to obtain the closest, human-readable address
56 57 58 |
# File 'lib/gmaps_geocoding/config.rb', line 56 def latlng @options[:latlng] end |
#output ⇒ String
Output format of the Google Maps Geocoding Service
39 40 41 |
# File 'lib/gmaps_geocoding/config.rb', line 39 def output @options[:output] end |
#region ⇒ String
The region code, specified as a ccTLD (“top-level domain”) two-character value
https://developers.google.com/maps/documentation/geocoding/#RegionCodes
94 95 96 |
# File 'lib/gmaps_geocoding/config.rb', line 94 def region @options[:region] end |
#sensor ⇒ String
Indicates whether or not the geocoding request comes from a device with a location sensor.
71 72 73 |
# File 'lib/gmaps_geocoding/config.rb', line 71 def sensor @options[:sensor] end |
#url ⇒ String
URL of the Google Maps Geocoding Service
32 33 34 |
# File 'lib/gmaps_geocoding/config.rb', line 32 def url @options[:url] end |
#valid? ⇒ true, false
Check if the configuration object is valid
101 102 103 |
# File 'lib/gmaps_geocoding/config.rb', line 101 def valid? query_valid? && output_param_valid? end |
#xml_format? ⇒ true, false
Check if the output format of the query is set to xml
115 116 117 |
# File 'lib/gmaps_geocoding/config.rb', line 115 def xml_format? 'xml'.eql?(output) end |