File: here.rb

package info (click to toggle)
ruby-geocoder 1.8.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 900 kB
  • sloc: ruby: 8,419; makefile: 3
file content (77 lines) | stat: -rw-r--r-- 1,355 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'geocoder/results/base'

module Geocoder::Result
  class Here < Base

    ##
    # A string in the given format.
    #
    def address(format = :full)
      address_data["label"]
    end

    ##
    # A two-element array: [lat, lon].
    #
    def coordinates
      fail unless d = @data["position"]
      [d["lat"].to_f, d["lng"].to_f]
    end
    
    def route
      address_data["street"]
    end
    
    def street_number
      address_data["houseNumber"]
    end  

    def state
      address_data["state"]
    end

    def province
      address_data["county"]
    end

    def postal_code
      address_data["postalCode"]
    end

    def city
      address_data["city"]
    end

    def state_code
      address_data["stateCode"]
    end

    def province_code
      address_data["state"]
    end

    def country
      address_data["countryName"]
    end

    def country_code
      address_data["countryCode"]
    end

    def viewport
      return [] if data["resultType"] == "place"
      map_view = data["mapView"]
      south = map_view["south"]
      west = map_view["west"]
      north = map_view["north"]
      east = map_view["east"]
      [south, west, north, east]
    end

    private # ----------------------------------------------------------------

    def address_data
      @data["address"] || fail
    end
  end
end