Class: GmapsGeocoding::Config

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

Overview

Configuration class for GmapsGeocoding API.

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

Returns a new instance of Config.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/gmaps_geocoding/config.rb', line 6

def initialize(opts = {})
  @options = {url: 'https://maps.googleapis.com/maps/api/geocode'}
  @options[:output]     = ENV['GOOGLE_MAPS_GEOCODING_OUTPUT']     || opts[:output]     || 'json'
  @options[:address]    = ENV['GOOGLE_MAPS_GEOCODING_ADDRESS']    || opts[:address]    || ''
  @options[:latlng]     = ENV['GOOGLE_MAPS_GEOCODING_LATLNG']     || opts[:latlng]     || ''
  @options[:components] = ENV['GOOGLE_MAPS_GEOCODING_COMPONENTS'] || opts[:components] || ''
  @options[:sensor]     = ENV['GOOGLE_MAPS_GEOCODING_SENSOR']     || opts[:sensor]     || 'false'
  @options[:bounds]     = ENV['GOOGLE_MAPS_GEOCODING_BOUNDS']     || opts[:bounds]     || ''
  @options[:language]   = ENV['GOOGLE_MAPS_GEOCODING_LANGUAGE']   || opts[:language]   || ''
  @options[:region]     = ENV['GOOGLE_MAPS_GEOCODING_REGION']     || opts[:region]     || ''
  @options.merge!(opts).reject!{|_, v| v.to_s.length == 0 }
end

Instance Method Details

#addressString

The address that you want to geocode

Returns:

  • (String)

    The address that you want to geocode.



36
37
38
# File 'lib/gmaps_geocoding/config.rb', line 36

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



68
69
70
# File 'lib/gmaps_geocoding/config.rb', line 68

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



53
54
55
# File 'lib/gmaps_geocoding/config.rb', line 53

def components
  @options[:components]
end

#is_json_format?true, false

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

Returns:

  • (true, false)

    Return true or false



97
98
99
# File 'lib/gmaps_geocoding/config.rb', line 97

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

#is_xml_format?true, false

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

Returns:

  • (true, false)

    Return true or false



104
105
106
# File 'lib/gmaps_geocoding/config.rb', line 104

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

#languageString

The language in which to return results

Returns:



75
76
77
# File 'lib/gmaps_geocoding/config.rb', line 75

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



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

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



29
30
31
# File 'lib/gmaps_geocoding/config.rb', line 29

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



83
84
85
# File 'lib/gmaps_geocoding/config.rb', line 83

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”.



60
61
62
# File 'lib/gmaps_geocoding/config.rb', line 60

def sensor
  @options[:sensor]
end

#urlString

URL of the Google Maps Geocoding Service

Returns:

  • (String)

    URL of the Google Maps Geocoding Service



22
23
24
# File 'lib/gmaps_geocoding/config.rb', line 22

def url
  @options[:url]
end

#valid?true, false

Check if the configuration object is valid

Returns:

  • (true, false)

    Return true or false



90
91
92
# File 'lib/gmaps_geocoding/config.rb', line 90

def valid?
  is_query_valid? && is_output_param_valid?
end