mirror of
https://github.com/wahyd4/Libr.git
synced 2026-08-09 12:56:14 +10:00
20 lines
440 B
Ruby
20 lines
440 B
Ruby
class Location < ActiveRecord::Base
|
|
belongs_to :user
|
|
|
|
attr_accessible :lng, :lat, :address, :user_id
|
|
|
|
|
|
def locations_within_kilos_of(kilo)
|
|
Location.all.to_a.keep_if { |location|
|
|
GIS::Distance.new(self.lat, self.lng, location.lat, location.lng).distance <= kilo and location != self
|
|
}
|
|
end
|
|
|
|
def users_within_kilos_of(kilo)
|
|
locations_within_kilos_of(kilo).map { |location|
|
|
location.user
|
|
}.uniq
|
|
end
|
|
|
|
end
|