Class: GmapsGeocoding::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/gmaps_geocoding/config.rb

Overview

Configuration class for GmapsGeocoding API.

Constant Summary collapse

VALID_KEYS =

Configuration valid keys

[:url, :output, :address, :latlng, :components, :sensor, :bounds, :language, :region].freeze
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.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gmaps_geocoding/config.rb', line 15

def initialize(opts = {})
  @options = {}
  @options.merge!(DEFAULT_CONFIG)
  opts.each do |k, _|
    next unless VALID_KEYS.include?(k)
    val = if k.eql?(:url)
            opts.delete(k)
          else
            ENV["GOOGLE_MAPS_GEOCODING_#{k.to_s.upcase}"] || opts.delete(k)
          end
    @options[k] = val if val
  end
end

Instance Method Details

#addressString

The address that you want to geocode

Returns:

  • (String)

    The address that you want to geocode.



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

def address
  @options[:address]
end

#boundsString

The bounding box of the viewport within which to bias geocode results more prominently

https://developers.google.com/maps/documentation/geocoding/#Viewports

Returns:

  • (String)

    The bounding box of the viewport within which to bias geocode results more prominently



79
80
81
# File 'lib/gmaps_geocoding/config.rb', line 79

def bounds
  @options[:bounds]
end

#componentsString

A component filter for which you wish to obtain a geocode

https://developers.google.com/maps/documentation/geocoding/#ComponentFiltering

Returns:

  • (String)

    A component filter for which you wish to obtain a geocode



64
65
66
# File 'lib/gmaps_geocoding/config.rb', line 64

def components
  @options[:components]
end

#json_format?true, false

Check if the output format of the query is set to json

Returns:

  • (true, false)

    Return true or false



108
109
110
# File 'lib/gmaps_geocoding/config.rb', line 108

def json_format?
  'json'.eql?(output)
end

#languageString

The language in which to return results

Returns:



86
87
88
# File 'lib/gmaps_geocoding/config.rb', line 86

def language
  @options[:language]
end

#latlngString

The textual latitude/longitude value for which you wish to obtain the closest, human-readable address

Examples:

"40.714224,-73.961452"

Returns:

  • (String)

    The textual latitude/longitude value for which you wish to obtain the closest, human-readable address



56
57
58
# File 'lib/gmaps_geocoding/config.rb', line 56

def latlng
  @options[:latlng]
end

#outputString

Output format of the Google Maps Geocoding Service

Returns:

  • (String)

    Output format of the Google Maps Geocoding Service. Only xml or json formats are available



39
40
41
# File 'lib/gmaps_geocoding/config.rb', line 39

def output
  @options[:output]
end

#regionString

The region code, specified as a ccTLD (“top-level domain”) two-character value

https://developers.google.com/maps/documentation/geocoding/#RegionCodes

Returns:

  • (String)

    The region code, specified as a ccTLD (“top-level domain”) two-character value



94
95
96
# File 'lib/gmaps_geocoding/config.rb', line 94

def region
  @options[:region]
end

#sensorString

Indicates whether or not the geocoding request comes from a device with a location sensor.

Returns:

  • (String)

    Indicates whether or not the geocoding request comes from a device with a location sensor. Must be either “true” or “false”.



71
72
73
# File 'lib/gmaps_geocoding/config.rb', line 71

def sensor
  @options[:sensor]
end

#urlString

URL of the Google Maps Geocoding Service

Returns:

  • (String)

    URL of the Google Maps Geocoding Service



32
33
34
# File 'lib/gmaps_geocoding/config.rb', line 32

def url
  @options[:url]
end

#valid?true, false

Check if the configuration object is valid

Returns:

  • (true, false)

    Return true or false



101
102
103
# File 'lib/gmaps_geocoding/config.rb', line 101

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



115
116
117
# File 'lib/gmaps_geocoding/config.rb', line 115

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