Class: GmapsGeocoding::Config

Inherits:
Object
  • Object
show all
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

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

Returns:

  • (true, false)

    Return true or false



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

Returns:

  • (true, false)

    Return true or false



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

Returns:

  • (true, false)

    Return true or false



47
48
49
# File 'lib/gmaps_geocoding/config.rb', line 47

def xml_format?
  'xml'.freeze.eql?(output)
end