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', output: 'json', sensor: 'false' }.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.
23 24 25 26 27 28 29 30 |
# File 'lib/gmaps_geocoding/config.rb', line 23 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
42 43 44 |
# File 'lib/gmaps_geocoding/config.rb', line 42 def json_format? 'json'.eql?(output) end |
#valid? ⇒ true, false
Check if the configuration object is valid
35 36 37 |
# File 'lib/gmaps_geocoding/config.rb', line 35 def valid? query_valid? && output_param_valid? end |
#xml_format? ⇒ true, false
Check if the output format of the query is set to xml
49 50 51 |
# File 'lib/gmaps_geocoding/config.rb', line 49 def xml_format? 'xml'.eql?(output) end |