Class: GeoRb::Location

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/geo_rb/location.rb

Overview

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address:, raw:, point: Point) ⇒ Location

Returns a new instance of Location.



18
19
20
21
22
# File 'lib/geo_rb/location.rb', line 18

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

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



12
13
14
# File 'lib/geo_rb/location.rb', line 12

def address
  @address
end

#pointObject (readonly)

Returns the value of attribute point.



12
13
14
# File 'lib/geo_rb/location.rb', line 12

def point
  @point
end

#rawObject (readonly)

Returns the value of attribute raw.



12
13
14
# File 'lib/geo_rb/location.rb', line 12

def raw
  @raw
end

Class Method Details

.lookup(text, adapter: GeoRb::GeoCoders::Nominatim, **options) ⇒ Object



14
15
16
# File 'lib/geo_rb/location.rb', line 14

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

Instance Method Details

#distance_to(location) ⇒ Object



24
25
26
# File 'lib/geo_rb/location.rb', line 24

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

#to_hObject



28
29
30
# File 'lib/geo_rb/location.rb', line 28

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