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',
  output: 'json',
  sensor: 'false'
}.freeze

Instance Method Summary collapse

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

Returns:

  • (true, false)

    Return true or false



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

Returns:

  • (true, false)

    Return true or false



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

Returns:

  • (true, false)

    Return true or false



49
50
51
# File 'lib/gmaps_geocoding/config.rb', line 49

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