Class: Misc::GeoPoint
- Inherits:
-
Object
- Object
- Misc::GeoPoint
- Includes:
- AttributesReader
- Defined in:
- lib/misc/geo_point.rb
Overview
Point Class
Instance Method Summary collapse
-
#initialize(lat: nil, lng: nil, latlng: nil, geo_hash: nil) ⇒ GeoPoint
constructor
A new instance of GeoPoint.
-
#settings ⇒ Hash
Serialized json query for object.
Methods included from AttributesReader
Constructor Details
#initialize(lat: nil, lng: nil, latlng: nil, geo_hash: nil) ⇒ GeoPoint
Returns a new instance of GeoPoint.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/misc/geo_point.rb', line 15 def initialize(lat: nil, lng: nil, latlng: nil, geo_hash: nil) if lat.present? && lng.present? @lat = lat.to_f @lng = lng.to_f @type = :float elsif latlng.present? @latlng = latlng @type = latlng.class.name.downcase.intern elsif geo_hash.present? @geo_hash = geo_hash @type = :geohash else raise 'Provide Point as floating values latitude and longitude or a string or an array or a geohash' end end |
Instance Method Details
#settings ⇒ Hash
Returns serialized json query for object.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/misc/geo_point.rb', line 33 def settings case @type when :float { lat: @lat, lon: @lng } when :array || :string @latlng when :geohash @geohash end end |