mongo_geo 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/lib/mongo_geo.rb CHANGED
@@ -75,6 +75,15 @@ module GeoSpatial
75
75
  dy = loc[1] - pt[1]
76
76
  Math.sqrt((dx ** 2) + (dy ** 2))
77
77
  end
78
+
79
+ def neighbors(opts = {})
80
+ opts = {:skip => 0, :limit => 10}.merge(opts)
81
+ location = self.class.geo_key_name.to_sym
82
+
83
+ self.class.name.constantize.where(
84
+ location.near => self.send(self.class.geo_key_name)
85
+ ).skip(opts[:skip]).limit(opts[:limit] + 1).to_a.reject { |n| n.id == self.id }
86
+ end
78
87
  end
79
88
  end
80
89
 
data/mongo_geo.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongo_geo}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Parrish"]
@@ -49,5 +49,15 @@ class TestMongoGeo < Test::Unit::TestCase
49
49
  TestAsset.collection.drop_indexes
50
50
  TestAsset.collection.remove
51
51
  end
52
+
53
+ should "find close objects with #neighbors" do
54
+ neighbors = @asset1.neighbors
55
+ assert_equal([@asset2, @asset3], neighbors)
56
+ end
57
+
58
+ should "find closest object with #neighbors" do
59
+ neighbors = @asset1.neighbors(:limit => 1)
60
+ assert_equal([@asset2], neighbors)
61
+ end
52
62
  end
53
63
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_geo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Parrish