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
Returns a new instance of Config.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/gmaps_geocoding/config.rb', line 6 def initialize(opts = {}) @options = {url: 'https://maps.googleapis.com/maps/api/geocode'} @options[:output] = ENV['GOOGLE_MAPS_GEOCODING_OUTPUT'] || opts[:output] || 'json' @options[:address] = ENV['GOOGLE_MAPS_GEOCODING_ADDRESS'] || opts[:address] || '' @options[:latlng] = ENV['GOOGLE_MAPS_GEOCODING_LATLNG'] || opts[:latlng] || '' @options[:components] = ENV['GOOGLE_MAPS_GEOCODING_COMPONENTS'] || opts[:components] || '' @options[:sensor] = ENV['GOOGLE_MAPS_GEOCODING_SENSOR'] || opts[:sensor] || 'false' @options[:bounds] = ENV['GOOGLE_MAPS_GEOCODING_BOUNDS'] || opts[:bounds] || '' @options[:language] = ENV['GOOGLE_MAPS_GEOCODING_LANGUAGE'] || opts[:language] || '' @options[:region] = ENV['GOOGLE_MAPS_GEOCODING_REGION'] || opts[:region] || '' @options.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 @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
68 69 70 |
# File 'lib/gmaps_geocoding/config.rb', line 68 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
53 54 55 |
# File 'lib/gmaps_geocoding/config.rb', line 53 def components @options[:components] end |
#is_json_format? ⇒ true, false
Check if the output format of the query is set to json
97 98 99 |
# File 'lib/gmaps_geocoding/config.rb', line 97 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
104 105 106 |
# File 'lib/gmaps_geocoding/config.rb', line 104 def is_xml_format? 'xml'.eql?(output) end |
#language ⇒ String
The language in which to return results
75 76 77 |
# File 'lib/gmaps_geocoding/config.rb', line 75 def language @options[: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 @options[: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 @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
83 84 85 |
# File 'lib/gmaps_geocoding/config.rb', line 83 def region @options[:region] end |
#sensor ⇒ String
Indicates whether or not the geocoding request comes from a device with a location sensor.
60 61 62 |
# File 'lib/gmaps_geocoding/config.rb', line 60 def sensor @options[:sensor] end |
#url ⇒ String
URL of the Google Maps Geocoding Service
22 23 24 |
# File 'lib/gmaps_geocoding/config.rb', line 22 def url @options[:url] end |
#valid? ⇒ true, false
Check if the configuration object is valid
90 91 92 |
# File 'lib/gmaps_geocoding/config.rb', line 90 def valid? is_query_valid? && is_output_param_valid? end |