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



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



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



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

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



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

def components
  @options[:components]
end

#is_json_format?true, false

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



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

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



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

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

#languageString

The language in which to return results



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

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"


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



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



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

def region
  @options[:region]
end

#sensorString

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



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

def sensor
  @options[:sensor]
end

#urlString

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



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

def valid?
  is_query_valid? && is_output_param_valid?
end