arel-haversine 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'arel'
22
+ spec.add_dependency 'arel-trigonometry'
22
23
 
23
24
  spec.add_development_dependency 'activerecord', '>= 3'
24
25
  spec.add_development_dependency 'bundler', '~> 1.3'
@@ -1,5 +1,5 @@
1
1
  module Arel
2
2
  module Haversine
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
@@ -1,10 +1,12 @@
1
+ require 'arel/trigonometry'
2
+
1
3
  module Arel
2
4
  module Nodes
3
5
  class Haversine < Function
4
6
  def initialize lat1, lng1, lat2, lng2, options = nil
5
7
  super Multiplication.new(
6
8
  Arcsine.new(
7
- Sqrt.new(
9
+ SquareRoot.new(
8
10
  Addition.new(
9
11
  Pow.new(Sine.new(Division.new(Radians.new(lat1 - lat2), 2)), 2),
10
12
  Multiplication.new(
@@ -26,56 +28,9 @@ module Arel
26
28
  (options || {})[:unit] == :mi ? 7917.5 : 12742
27
29
  end
28
30
  end
29
-
30
- %w[
31
- Arcsine
32
- Cosine
33
- Radians
34
- Sine
35
- Sqrt
36
- ].each do |name|
37
- const_set name, Class.new(Unary)
38
- end
39
- Pow = Class.new(Binary)
40
31
  end
41
32
 
42
33
  module Visitors
43
- module CommonMathVisitors
44
- private
45
-
46
- def visit_Arel_Nodes_Arcsine o
47
- "ASIN(#{visit o.expr})"
48
- end
49
-
50
- def visit_Arel_Nodes_Cosine o
51
- "COS(#{visit o.expr})"
52
- end
53
-
54
- def visit_Arel_Nodes_Pow o
55
- "POW(#{visit o.left}, #{visit o.right})"
56
- end
57
-
58
- def visit_Arel_Nodes_Radians o
59
- "RADIANS(#{visit o.expr})"
60
- end
61
-
62
- def visit_Arel_Nodes_Sine o
63
- "SIN(#{visit o.expr})"
64
- end
65
-
66
- def visit_Arel_Nodes_Sqrt o
67
- "SQRT(#{visit o.expr})"
68
- end
69
- end
70
-
71
- class MySQL
72
- include CommonMathVisitors
73
- end
74
-
75
- class PostgreSQL
76
- include CommonMathVisitors
77
- end
78
-
79
34
  class ToSql
80
35
  private
81
36
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel-haversine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: arel-trigonometry
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: activerecord
32
48
  requirement: !ruby/object:Gem::Requirement