File: osmnames.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 (56 lines) | stat: -rw-r--r-- 972 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
require 'geocoder/results/base'

module Geocoder::Result
  class Osmnames < Base
    def address
      @data['display_name']
    end

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

    def viewport
      west, south, east, north = @data['boundingbox'].map(&:to_f)
      [south, west, north, east]
    end

    def state
      @data['state']
    end
    alias_method :state_code, :state

    def place_class
      @data['class']
    end

    def place_type
      @data['type']
    end

    def postal_code
      ''
    end

    def country_code
      @data['country_code']
    end

    def country
      @data['country']
    end

    def self.response_attributes
      %w[house_number street city name osm_id osm_type boundingbox place_rank
      importance county rank name_suffix]
    end

    response_attributes.each do |a|
      unless method_defined?(a)
        define_method a do
          @data[a]
        end
      end
    end
  end
end