File: latlon.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,211 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 Latlon < Base

    def city
      address_components["city"]
    end

    def coordinates
      [@data['lat'].to_f, @data['lon'].to_f]
    end

    def country
      "United States" # LatLon.io only supports the US
    end

    def country_code
      "US" # LatLon.io only supports the US
    end

    def formatted_address(format = :full)
      address_components["address"]
    end
    alias_method :address, :formatted_address

    def number
      address_components["number"]
    end

    def prefix
      address_components["prefix"]
    end

    def state
      address_components["state"]
    end
    alias_method :state_code, :state

    def street
      [street_name, street_type].compact.join(' ')
    end

    def street_name
      address_components["street_name"]
    end

    def street_type
      address_components["street_type"]
    end

    def suffix
      address_components["suffix"]
    end

    def unit
      address_components["unit"]
    end

    def zip
      address_components["zip"]
    end
    alias_method :postal_code, :zip

    private

    def address_components
      @data["address"] || {}
    end
  end
end