From 727f6dcee654f34b861f9a36fbfa904abfbb73dd Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Tue, 17 Jul 2012 09:48:17 -0700 Subject: [PATCH] --- post.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 post.rb diff --git a/post.rb b/post.rb new file mode 100644 index 0000000..3841336 --- /dev/null +++ b/post.rb @@ -0,0 +1,26 @@ +class Post + include MongoMapper::Document + + key :title, String + key :url, String + key :author, String + key :summary, String + key :content, String + key :published, Time + key :loc, Hash # { lng, lat } + timestamps! + + ensure_index [[:loc, '2d']] + + belongs_to :feed + + EARTH_RADIUS_M = 6378000 + + def self.near(lat, lng, radius_m) + all( + :loc => { + '$nearSphere' => [ lng, lat ], + '$maxDistance' => radius_m / EARTH_RADIUS_M + }) + end +end