geocoder-neo4j_spatial 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57b79c9ae93a2976c8b4cfd20ab54d2dd7a43798
4
- data.tar.gz: 443004f5e33232627807efed17677a9ad719ba52
3
+ metadata.gz: 1414165c59044babc2c24f02a1b2d9539e4f66f1
4
+ data.tar.gz: 74bfbb8d7fe2d1fe81c063ccc402156382049747
5
5
  SHA512:
6
- metadata.gz: 798d58b3e37a7484f61904613833670462f92f42e67b069135a87187ff99f6960f320e8fd57beceaa5ff7943c2c0ed3723eb43e551e6928e76588cfcad9aadf3
7
- data.tar.gz: 4ef9eb3cce5466009a3817beeabc533b5cb23ffeed49c208e0ed98bfc962f57cc3af56cc36f7a005fc0abf98b2ca000e0edaa22bea8bcb1f2aff7343527c939f
6
+ metadata.gz: 40c8aa7f3cf0749529d195663f808fee68b9367117c0fb6eb030d77dbb67bf5d4cdd6ed3e31ecc9f89704cf157a113552fc9d094a0f0d818d5a9cc98d86d3239
7
+ data.tar.gz: bf0536a402d7ef01a05e09c8ddec48a0a8ab8dc77787f42bf90c40adb48f699e6b5a59b7beba12f1f7f98afacac198700006a22e407cc77b1243b9e27cbe4c2e
data/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # Geocoder::Neo4jSpatial
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/geocoder/neo4j_spatial`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
3
  ## Installation
8
4
 
9
5
  Add this line to your application's Gemfile:
@@ -46,10 +42,21 @@ end
46
42
  Restaurant.near(location: 'Eiffel Tower', radius: 10.0).to_a
47
43
  ```
48
44
 
45
+ or
46
+
47
+ ```ruby
48
+ Restaurant.near(location: [48.85837009999999, 2.2944813], radius: 10.0).to_a
49
+ ```
50
+
51
+ will generate following query:
52
+
49
53
  ```
50
54
  CYPHER 9ms START result_restaurant = node:restaurants({spatial_params}) MATCH (result_restaurant:`Restaurant`) MATCH (result_restaurant:`Restaurant`) RETURN result_restaurant | {:spatial_params=>"withinDistance:[48.85837009999999, 2.2944813, 10.0]"}
51
55
  ```
52
56
 
57
+ * not implemented yet
58
+ - within_bounding_box
59
+
53
60
  ## Development
54
61
 
55
62
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,5 +1,5 @@
1
1
  module Geocoder
2
2
  module Neo4jSpatial
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -15,17 +15,27 @@ module Geocoder::Store
15
15
  }
16
16
 
17
17
  scope :near, -> (location:, radius:) {
18
- coordinates = Geocoder::Calculations.extract_coordinates(location)
18
+ if location.is_a?(Array)
19
+ coordinates = location << radius.to_f
19
20
 
20
- if Geocoder::Calculations.coordinates_present?(*coordinates)
21
- coordinates << radius
22
-
23
- query_proxy = instance_variable_get(:@query_proxy)
24
- spatial_match(query_proxy.node_identity, "withinDistance:#{coordinates}")
21
+ within(coordinates)
25
22
  else
26
- []
23
+ coordinates = Geocoder::Calculations.extract_coordinates(location)
24
+
25
+ if Geocoder::Calculations.coordinates_present?(*coordinates)
26
+ coordinates << radius.to_f
27
+
28
+ within(coordinates)
29
+ else
30
+ []
31
+ end
27
32
  end
28
33
  }
34
+
35
+ scope :within, -> (coordinates) {
36
+ query_proxy = instance_variable_get(:@query_proxy)
37
+ spatial_match(query_proxy.node_identity, "withinDistance:#{coordinates}")
38
+ }
29
39
  end
30
40
  end
31
41
 
@@ -33,8 +43,10 @@ module Geocoder::Store
33
43
  do_lookup(false) do |o, rs|
34
44
  if r = rs.first
35
45
  unless r.latitude.nil? or r.longitude.nil?
36
- o.__send__ "#{self.class.geocoder_options[:latitude]}=", r.latitude
37
- o.__send__ "#{self.class.geocoder_options[:longitude]}=", r.longitude
46
+ o.__send__ "#{self.class.geocoder_options[:latitude]}=", r.latitude
47
+ o.__send__ "#{self.class.geocoder_options[:longitude]}=", r.longitude
48
+
49
+ o.add_to_spatial_index o.class.spatial_index_name
38
50
  end
39
51
 
40
52
  r.coordinates
@@ -53,5 +65,11 @@ module Geocoder::Store
53
65
  end
54
66
  end
55
67
  end
68
+
69
+ def nearbys(radius = 20)
70
+ return nil unless geocoded?
71
+
72
+ self.class.near(location: to_coordinates, radius: radius)
73
+ end
56
74
  end
57
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geocoder-neo4j_spatial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kajisha
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2015-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: neo4j