Module: Geocoder::Store::Neo4j

Includes:
Base
Defined in:
lib/geocoder/stores/neo4j.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/geocoder/stores/neo4j.rb', line 7

def self.included(base)
  base.class_eval do
    scope :geocoded, -> {
      where_not(base.geocoder_options[:latitude] => nil, base.geocoder_options[:longitude] => nil)
    }

    scope :not_geocoded, -> {
      where(base.geocoder_options[:latitude] => nil, base.geocoder_options[:longitude] => nil)
    }

    scope :near, -> (location:, radius:) {
      coordinates = Geocoder::Calculations.extract_coordinates(location)

      if Geocoder::Calculations.coordinates_present?(*coordinates)
        coordinates << radius

        query_proxy = instance_variable_get(:@query_proxy)
        spatial_match(query_proxy.node_identity, "withinDistance:#{coordinates}")
      else
        []
      end
    }
  end
end

Instance Method Details

#geocodeObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/geocoder/stores/neo4j.rb', line 32

def geocode
  do_lookup(false) do |o, rs|
    if r = rs.first
      unless r.latitude.nil? or r.longitude.nil?
        o.__send__  "#{self.class.geocoder_options[:latitude]}=",  r.latitude
        o.__send__  "#{self.class.geocoder_options[:longitude]}=", r.longitude
      end

      r.coordinates
    end
  end
end

#reverse_geocodeObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/geocoder/stores/neo4j.rb', line 45

def reverse_geocode
  do_lookup(true) do |o, rs|
    if r = rs.first
      unless r.address.nil?
        o.__send__ "#{self.class.geocoder_options[:fetched_address]}=", r.address
      end

      r.address
    end
  end
end