open_places 0.0.1 → 0.0.2

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: 0cdc326660edafa4625ac7628cc95168927493b8
4
- data.tar.gz: fd1541155d81556d3fbd253b6338716500ec8fd3
3
+ metadata.gz: 8ebc05f7e2896ab593680b3ed93bb6e5263de0d7
4
+ data.tar.gz: ac3dc9718e63adac690b42bd285f221f51a6e1ee
5
5
  SHA512:
6
- metadata.gz: d1c423a0b2601e8c4d48d2330d9658ecc09b59b5093be855d74b72ccb59b32a7c743a7300c5815c2ba0ee338616e757e35b2b6661cff1ccd08d6bfe026e07288
7
- data.tar.gz: 494cd92eaa5762edb13fdf781efc5585975ef52563ed7035abbb08c25bf518c66a14955789020415a2a079fb10795b7b6af3140b31dce56b18183a935d9a7c72
6
+ metadata.gz: 3ee5557cef56c3f3692810ac0d3ae22bb9b35f7ab97134874093f7be06c04186fe176409cabf812cf365ba42b52fc8480a90b666dac805248bd6161398517ecb
7
+ data.tar.gz: 7a14007363c7e6e1535fe2a6e6800867e094b53277a5b35019453c9391657b20c9d0868dd66e23441ef9ba391827f07481cade5275e7a18aa402a5b5e257caa8
@@ -9,9 +9,9 @@ module OpenPlaces
9
9
  op = (params.keys & ['q', 'like', 'contains', 'starts', 'ends']).flatten.shift
10
10
  @results = OpenPlaces::Geo
11
11
  @results = @results.where(geotype: params[:type].split(",").map{|t| "OpenPlaces::#{t}" }) if params[:type].present?
12
- @results = @results.near(params[:near]) if params[:near].present?
13
- @results = @results.autocomplete(query_string, op) if query_string.present?
14
12
  @results = @results.order('scalerank ASC')
13
+ @results = @results.autocomplete(query_string, op) if query_string.present?
14
+ @results = @results.near(params[:near]) if params[:near].present?
15
15
  @results = @results.limit(params[:limit])
16
16
 
17
17
  respond_to do |format|
@@ -37,13 +37,14 @@ module OpenPlaces
37
37
  end
38
38
  }
39
39
 
40
- scope :near, -> (here=false, within='5', query=self.all){
40
+ scope :near, -> (here=false, query=self.all){
41
41
  return query unless here
42
42
  select("*,round(cast((ST_Distance_Sphere(latlng, ST_SetSRID(ST_MakePoint(#{here.toLngLat}), 4326))*0.000621371) AS NUMERIC),2) AS distance").order("latlng <-> st_setsrid(st_makepoint(#{here.toLngLat}),4326) ASC")
43
43
  }
44
44
 
45
- scope :ordered, -> (query=self.all){
46
- order('scalerank ASC')
45
+ scope :within, -> (here=false, within='5', query=self.all){
46
+ return query unless here
47
+ where("ST_DWithin(latlng, ST_SetSRID(ST_MakePoint(#{here.toLngLat}), 4326), #{within})")
47
48
  }
48
49
 
49
50
  scope :to_geojson, -> (field="geom", query=self.all) {
@@ -1,3 +1,3 @@
1
1
  module OpenPlaces
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_places
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ty Rauber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-29 00:00:00.000000000 Z
11
+ date: 2015-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails