Class: GmapsGeocoding::Config
- Inherits:
-
Object
- Object
- GmapsGeocoding::Config
- Defined in:
- lib/gmaps_geocoding/config.rb
Overview
Configuration class for GmapsGeocoding API.
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.
-
#is_json_format? ⇒ true, false
Check if the output format of the query is set to json.
-
#is_xml_format? ⇒ true, false
Check if the output format of the query is set to xml.
-
#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.
Constructor Details
#initialize(opts = {}) ⇒ Config
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/gmaps_geocoding/config.rb', line 6 def initialize(opts = {}) = { url: 'https://maps.googleapis.com/maps/api/geocode' } [:output] = ENV['GOOGLE_MAPS_GEOCODING_OUTPUT'] || opts[:output] || 'json' [:address] = ENV['GOOGLE_MAPS_GEOCODING_ADDRESS'] || opts[:address] || '' [:latlng] = ENV['GOOGLE_MAPS_GEOCODING_LATLNG'] || opts[:latlng] || '' [:components] = ENV['GOOGLE_MAPS_GEOCODING_COMPONENTS'] || opts[:components] || '' [:sensor] = ENV['GOOGLE_MAPS_GEOCODING_SENSOR'] || opts[:sensor] || 'false' [:bounds] = ENV['GOOGLE_MAPS_GEOCODING_BOUNDS'] || opts[:bounds] || '' [:language] = ENV['GOOGLE_MAPS_GEOCODING_LANGUAGE'] || opts[:language] || '' [:region] = ENV['GOOGLE_MAPS_GEOCODING_REGION'] || opts[:region] || '' .merge!(opts).reject! { |_, v| v.to_s.length == 0 } end |
Instance Method Details
#address ⇒ String
The address that you want to geocode
36 37 38 |
# File 'lib/gmaps_geocoding/config.rb', line 36 def address [: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
69 70 71 |
# File 'lib/gmaps_geocoding/config.rb', line 69 def bounds [:bounds] end |
#components ⇒ String
A component filter for which you wish to obtain a geocode
https://developers.google.com/maps/documentation/geocoding/#ComponentFiltering
54 55 56 |
# File 'lib/gmaps_geocoding/config.rb', line 54 def components [:components] end |
#is_json_format? ⇒ true, false
Check if the output format of the query is set to json
98 99 100 |
# File 'lib/gmaps_geocoding/config.rb', line 98 def is_json_format? 'json'.eql?(output) end |
#is_xml_format? ⇒ true, false
Check if the output format of the query is set to xml
105 106 107 |
# File 'lib/gmaps_geocoding/config.rb', line 105 def is_xml_format? 'xml'.eql?(output) end |
#language ⇒ String
The language in which to return results
76 77 78 |
# File 'lib/gmaps_geocoding/config.rb', line 76 def language [:language] end |
#latlng ⇒ String
The textual latitude/longitude value for which you wish to obtain the closest, human-readable address
46 47 48 |
# File 'lib/gmaps_geocoding/config.rb', line 46 def latlng [:latlng] end |
#output ⇒ String
Output format of the Google Maps Geocoding Service
29 30 31 |
# File 'lib/gmaps_geocoding/config.rb', line 29 def output [: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
84 85 86 |
# File 'lib/gmaps_geocoding/config.rb', line 84 def region [:region] end |
#sensor ⇒ String
Indicates whether or not the geocoding request comes from a device with a location sensor.
61 62 63 |
# File 'lib/gmaps_geocoding/config.rb', line 61 def sensor [:sensor] end |
#url ⇒ String
URL of the Google Maps Geocoding Service
22 23 24 |
# File 'lib/gmaps_geocoding/config.rb', line 22 def url [:url] end |
#valid? ⇒ true, false
Check if the configuration object is valid
91 92 93 |
# File 'lib/gmaps_geocoding/config.rb', line 91 def valid? is_query_valid? && is_output_param_valid? end |