Sha256: 8d39d06f61879eb7b6ec26c3e26c4a02ee8eef5ebd6c7f7d948f35e05cd04725

Contents?: true

Size: 1.65 KB

Versions: 6

Compression:

Stored size: 1.65 KB

Contents

module Nominatim
  class Place
    # attr_reader :attrs
    # alias to_hash attrs

    def initialize(attrs = {})
      @attrs = attrs
    end

    # Return display name
    #
    # @return [String]
    def display_name
      @display_name ||= @attrs[:display_name]
    end

    # Return a class
    #
    # @return [String]
    def class
      @class ||= @attrs[:class]
    end

    # Return a type
    #
    # @return [String]
    def type
      @type ||= @attrs[:type]
    end

    # Return an address
    #
    # @return [Nominatim::Address]
    def address
      @address ||= Nominatim::Address.new(@attrs[:address]) if @attrs[:address]
    end

    # Return a latitude
    #
    # @return [Float]
    def lat
      point.lat
    end
    alias latitude lat

    # Return a longitude
    #
    # @return [Float]
    def lon
      point.lon
    end
    alias longitude lon

    def boundingbox
      @boundingbox ||= @attrs[:boundingbox]
    end
    alias bounding_box boundingbox

    # Return a polygon
    #
    # @return [Nominatim::Polygon]
    def polygonpoints
      @polygonpoints ||= Nominatim::Polygon.new(@attrs[:polygonpoints]) if @attrs[:polygonpoints]
    end

    # Return a place id
    #
    # @return [Integer]
    def place_id
      @place_id ||= @attrs[:place_id].to_i if @attrs[:place_id]
    end

    # Return an OSM id
    #
    # @return [Integer]
    def osm_id
      @osm_id ||= @attrs[:osm_id].to_i if @attrs[:osm_id]
    end

    # Return an OSM type
    #
    # @return [String]
    def osm_type
      @osm_type ||= @attrs[:osm_type]
    end

    private

    def point
      @point ||= Nominatim::Point.new(@attrs[:lat], @attrs[:lon])
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
nominatim-0.0.6 lib/nominatim/place.rb
ruby-nominatim-1.0.0 lib/nominatim/place.rb
parallel588_nominatim-0.0.7 lib/nominatim/place.rb
nominatim-0.0.5 lib/nominatim/place.rb
nominatim-0.0.4 lib/nominatim/place.rb
nominatim-0.0.3 lib/nominatim/place.rb