Sha256: f0b53f40c122c93f0fc72f42f0f3cd06dfc32a7a82854745e9e0ae86367aecc9

Contents?: true

Size: 870 Bytes

Versions: 2

Compression:

Stored size: 870 Bytes

Contents

require "forwardable"

module GeoRb
  # Contains a parsed geocoder response. Can be iterated over as
  # ``(location<String>, (latitude<float>, longitude<Float))``.
  #  Or one can access the properties ``address``, ``latitude``,
  #  ``longitude``, or ``raw``. The last
  #  is a dictionary of the geocoder's response for this item.
  class Location
    extend Forwardable
    def_delegators :point, :latitude, :longitude, :altitude
    attr_reader :address, :point, :raw

    def self.lookup(text, adapter: GeoRb::GeoCoders::Nominatim, **options)
      adapter.new.geocode(text, **options)
    end

    def initialize(address:, raw:, point: Point)
      @address = address
      @point = point
      @raw = raw
    end

    def distance_to(location)
      Distance.new(self, location)
    end

    def to_h
      {address: address}.merge(point.to_h)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geo_rb-0.0.2 lib/geo_rb/location.rb
geo_rb-0.0.1 lib/geo_rb/location.rb