File: tencent.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 (72 lines) | stat: -rw-r--r-- 1,753 bytes parent folder | download | duplicates (2)
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
require 'geocoder/results/base'

module Geocoder::Result
  class Tencent < Base

    def coordinates
      ['lat', 'lng'].map{ |i| @data['location'][i] }
    end

    def address
      "#{province}#{city}#{district}#{street}#{street_number}"

      #@data['title'] or @data['address']
    end

    # NOTE: The Tencent reverse geocoding API has the field named
    # 'address_component' compared to 'address_components' in the 
    # regular geocoding API.
    def province
      @data['address_components'] and (@data['address_components']['province']) or 
      (@data['address_component'] and @data['address_component']['province']) or
      ""
    end

    alias_method :state, :province

    def city
      @data['address_components'] and (@data['address_components']['city']) or 
      (@data['address_component'] and @data['address_component']['city']) or
      ""
    end

    def district
      @data['address_components'] and (@data['address_components']['district']) or 
      (@data['address_component'] and @data['address_component']['district']) or
      ""
    end

    def street
      @data['address_components'] and (@data['address_components']['street']) or 
      (@data['address_component'] and @data['address_component']['street']) or
      ""
    end

    def street_number
      @data['address_components'] and (@data['address_components']['street_number']) or 
      (@data['address_component'] and @data['address_component']['street_number']) or
      ""
    end

    def address_components
      @data['address_components'] or @data['address_component']
    end

    def state_code
      ""
    end

    def postal_code
      ""
    end

    def country
      "China"
    end

    def country_code
      "CN"
    end

  end
end