File: geoportail_lu.rb

package info (click to toggle)
ruby-geocoder 1.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 732 kB
  • sloc: ruby: 6,173; makefile: 3
file content (71 lines) | stat: -rw-r--r-- 1,233 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
require 'geocoder/results/base'

module Geocoder::Result
  class GeoportailLu < Base

    def coordinates
      geomlonlat['coordinates'].reverse if geolocalized?
    end

    def address
      full_address
    end

    def city
      try_to_extract 'locality', detailled_address
    end

    def state
      'Luxembourg'
    end

    def state_code
      'LU'
    end

    def postal_code
      try_to_extract 'zip', detailled_address
    end

    def street_address
      [street_number, street].compact.join(' ')
    end

    def street_number
      try_to_extract 'postnumber', detailled_address
    end

    def street
      try_to_extract 'street', detailled_address
    end

    def full_address
      data['address']
    end

    def geomlonlat
      data['geomlonlat']
    end

    def detailled_address
      data['AddressDetails']
    end

    alias_method :country, :state
    alias_method :province, :state
    alias_method :country_code, :state_code
    alias_method :province_code, :state_code

    private

    def geolocalized?
      !!try_to_extract('coordinates', geomlonlat)
    end

    def try_to_extract(key, hash)
      if hash.is_a?(Hash) and hash.include?(key)
        hash[key]
      end
    end
  end
end