geocoder-neo4j_spatial 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 57b79c9ae93a2976c8b4cfd20ab54d2dd7a43798
4
+ data.tar.gz: 443004f5e33232627807efed17677a9ad719ba52
5
+ SHA512:
6
+ metadata.gz: 798d58b3e37a7484f61904613833670462f92f42e67b069135a87187ff99f6960f320e8fd57beceaa5ff7943c2c0ed3723eb43e551e6928e76588cfcad9aadf3
7
+ data.tar.gz: 4ef9eb3cce5466009a3817beeabc533b5cb23ffeed49c208e0ed98bfc962f57cc3af56cc36f7a005fc0abf98b2ca000e0edaa22bea8bcb1f2aff7343527c939f
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'neo4jrb_spatial', github: 'kajisha/neo4jrb_spatial'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 kajisha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,62 @@
1
+ # Geocoder::Neo4jSpatial
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
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'geocoder-neo4j_spatial'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install geocoder-neo4j_spatial
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ class Restaurant
27
+ extend Geocoder::Model::ActiveNode
28
+
29
+ include Neo4j::ActiveNode
30
+ include Neo4j::ActiveNode::Spatial
31
+
32
+ property :address
33
+ property :latitude
34
+ property :longitude
35
+
36
+ geocoded_by :address
37
+ after_validation :address, if: :address_changed?
38
+
39
+ spatial_index :restaurants
40
+ end
41
+ ```
42
+
43
+ * Query within distance
44
+
45
+ ```ruby
46
+ Restaurant.near(location: 'Eiffel Tower', radius: 10.0).to_a
47
+ ```
48
+
49
+ ```
50
+ 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
+ ```
52
+
53
+ ## Development
54
+
55
+ 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.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kajisha/geocoder-neo4j_spatial.
62
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "geocoder/neo4j_spatial"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'geocoder/neo4j_spatial/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'geocoder-neo4j_spatial'
7
+ spec.version = Geocoder::Neo4jSpatial::VERSION
8
+ spec.authors = ['kajisha']
9
+ spec.email = ['kajisha@gmail.com']
10
+
11
+ spec.summary = %q{Geocoder for neo4j_spatial}
12
+ spec.description = %q{Geocoder for neo4j_spatial}
13
+ spec.homepage = 'https://github.com/kajisha/geocoder-neo4j_spatial'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = 'exe'
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'neo4j'
21
+ spec.add_dependency 'geocoder'
22
+
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ end
@@ -0,0 +1,48 @@
1
+ require 'geocoder/models/base'
2
+
3
+ module Geocoder
4
+ module Model
5
+ module ActiveNode
6
+ include Base
7
+
8
+ def geocoded_by(address_attr, options = {}, &block)
9
+ geocoder_init(
10
+ geocode: true,
11
+ user_address: address_attr,
12
+ latitude: options[:latitude] || :latitude,
13
+ longitude: options[:longitude] || :longitude,
14
+ geocode_block: block,
15
+ units: options[:units],
16
+ method: options[:method],
17
+ lookup: options[:lookup],
18
+ language: options[:language]
19
+ )
20
+ end
21
+
22
+ def reverse_geocoded_by(latitude_attr, longitude_attr, options = {}, &block)
23
+ geocoder_init(
24
+ reverse_geocode: true,
25
+ fetched_address: options[:address] || :address,
26
+ latitude: latitude_attr,
27
+ longitude: longitude_attr,
28
+ geocode_block: block,
29
+ units: options[:units],
30
+ method: options[:method],
31
+ lookup: options[:lookup],
32
+ language: options[:language]
33
+ )
34
+ end
35
+
36
+ def geocoder_init(options)
37
+ unless defined?(@geocoder_options)
38
+ @geocoder_options = {}
39
+
40
+ require 'geocoder/stores/neo4j'
41
+ include Geocoder::Store::Neo4j
42
+ end
43
+
44
+ @geocoder_options = options
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,8 @@
1
+ require 'geocoder/neo4j_spatial/version'
2
+ require 'geocoder/model/active_node'
3
+ require 'geocoder/stores/neo4j'
4
+
5
+ module Geocoder
6
+ module Neo4jSpatial
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Geocoder
2
+ module Neo4jSpatial
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,57 @@
1
+ require 'geocoder/stores/base'
2
+
3
+ module Geocoder::Store
4
+ module Neo4j
5
+ include Base
6
+
7
+ def self.included(base)
8
+ base.class_eval do
9
+ scope :geocoded, -> {
10
+ where_not(base.geocoder_options[:latitude] => nil, base.geocoder_options[:longitude] => nil)
11
+ }
12
+
13
+ scope :not_geocoded, -> {
14
+ where(base.geocoder_options[:latitude] => nil, base.geocoder_options[:longitude] => nil)
15
+ }
16
+
17
+ scope :near, -> (location:, radius:) {
18
+ coordinates = Geocoder::Calculations.extract_coordinates(location)
19
+
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}")
25
+ else
26
+ []
27
+ end
28
+ }
29
+ end
30
+ end
31
+
32
+ def geocode
33
+ do_lookup(false) do |o, rs|
34
+ if r = rs.first
35
+ 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
38
+ end
39
+
40
+ r.coordinates
41
+ end
42
+ end
43
+ end
44
+
45
+ def reverse_geocode
46
+ do_lookup(true) do |o, rs|
47
+ if r = rs.first
48
+ unless r.address.nil?
49
+ o.__send__ "#{self.class.geocoder_options[:fetched_address]}=", r.address
50
+ end
51
+
52
+ r.address
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geocoder-neo4j_spatial
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kajisha
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: neo4j
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: geocoder
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Geocoder for neo4j_spatial
84
+ email:
85
+ - kajisha@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - geocoder-neo4j_spatial.gemspec
100
+ - lib/geocoder/model/active_node.rb
101
+ - lib/geocoder/neo4j_spatial.rb
102
+ - lib/geocoder/neo4j_spatial/version.rb
103
+ - lib/geocoder/stores/neo4j.rb
104
+ homepage: https://github.com/kajisha/geocoder-neo4j_spatial
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.5.1
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Geocoder for neo4j_spatial
127
+ test_files: []