Class: Twofishes::GeocodeRequest

Inherits:
GeocodeRequest show all
Defined in:
lib/twofishes/geocode_request.rb

Constant Summary

Constants inherited from GeocodeRequest

GeocodeRequest::ALLOWEDSOURCES, GeocodeRequest::AUTOCOMPLETE, GeocodeRequest::AUTOCOMPLETEBIAS, GeocodeRequest::BOUNDS, GeocodeRequest::CC, GeocodeRequest::DEBUG, GeocodeRequest::FIELDS, GeocodeRequest::FULL_DEPRECATED, GeocodeRequest::INCLUDEPOLYGON_DEPRECATED, GeocodeRequest::LANG, GeocodeRequest::LL, GeocodeRequest::MAXINTERPRETATIONS, GeocodeRequest::QUERY, GeocodeRequest::RADIUS, GeocodeRequest::RESPONSEINCLUDES, GeocodeRequest::SLUG, GeocodeRequest::STRICT, GeocodeRequest::WOEHINT, GeocodeRequest::WOERESTRICT

Instance Method Summary collapse

Methods inherited from GeocodeRequest

#struct_fields, #validate

Constructor Details

#initialize(options = {}) ⇒ GeocodeRequest

Returns a new instance of GeocodeRequest.



3
4
5
6
7
8
9
10
# File 'lib/twofishes/geocode_request.rb', line 3

def initialize(options = {})
  options = substitute_aliases(options)

  options[:ll] = prepare_ll(options[:ll])
  options[:bounds] = prepare_bounds(options[:bounds])

  super(options)
end

Instance Method Details

#prepare_bounds(bounds) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/twofishes/geocode_request.rb', line 26

def prepare_bounds(bounds)
  case bounds
  when String
    ne_lat, ne_lng, sw_lat, sw_lng = bounds.split(/\s*,\s*/)
    new_bounding_box(ne_lat, ne_lng, sw_lat, sw_lng)
  when Array
    new_bounding_box(bounds[0], bounds[1], bounds[2], bounds[3])
  when Hash
    new_bounding_box(bounds[:ne_lat], bounds[:ne_lng], bounds[:sw_lat], bounds[:sw_lng])
  else
    bounds
  end
end

#prepare_ll(ll) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/twofishes/geocode_request.rb', line 12

def prepare_ll(ll)
  case ll
  when String
    lat, lng = ll.split(/\s*,\s*/)
    new_point(lat, lng)
  when Array
    new_point(ll[0], ll[1])
  when Hash
    new_point(ll[:lat], ll[:lng])
  else
    ll
  end
end

#substitute_aliases(options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/twofishes/geocode_request.rb', line 40

def substitute_aliases(options)
  options = Hash[options.map { |k, v| [k.to_s.camelize(:lower).to_sym, v] }]

  options[:maxInterpretations] ||= options.delete(:max)
  options[:allowedSources] ||= options.delete(:sources)
  options[:responseIncludes] ||= options.delete(:includes)
  options[:autocompleteBias] ||= options.delete(:bias)

  options
end