Class: GmapsGeocoding::Config
- Inherits:
-
Object
- Object
- GmapsGeocoding::Config
- Defined in:
- lib/gmaps_geocoding/config.rb
Overview
Configuration class for GmapsGeocoding API.
Constant Summary collapse
- DEFAULT_CONFIG =
Default configuration values
{ url: 'https://maps.googleapis.com/maps/api/geocode'.freeze, output: 'json'.freeze, sensor: 'false'.freeze }.freeze
Instance Method Summary collapse
-
#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.
-
#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.
21 22 23 24 25 26 27 28 |
# File 'lib/gmaps_geocoding/config.rb', line 21 def initialize(opts = {}) opts = DEFAULT_CONFIG.merge(opts) VALID_KEYS.each do |k, _| next unless VALID_KEYS.include?(k) val = ENV["GOOGLE_MAPS_GEOCODING_#{k.to_s.upcase}"] || opts.delete(k) send("#{k}=", val) if val end end |
Instance Method Details
#json_format? ⇒ true, false
Check if the output format of the query is set to json
40 41 42 |
# File 'lib/gmaps_geocoding/config.rb', line 40 def json_format? 'json'.freeze.eql?(output) end |
#valid? ⇒ true, false
Check if the configuration object is valid
33 34 35 |
# File 'lib/gmaps_geocoding/config.rb', line 33 def valid? query_valid? && output_param_valid? end |
#xml_format? ⇒ true, false
Check if the output format of the query is set to xml
47 48 49 |
# File 'lib/gmaps_geocoding/config.rb', line 47 def xml_format? 'xml'.freeze.eql?(output) end |