server-side-google-maps 0.0.4 → 0.0.5

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.
@@ -90,6 +90,10 @@ module ServerSideGoogleMaps
90
90
  @distance ||= calculate_distance
91
91
  end
92
92
 
93
+ def estimated_distance
94
+ @estimated_distance ||= calculate_estimated_distance
95
+ end
96
+
93
97
  private
94
98
 
95
99
  def origin_point_without_server
@@ -131,11 +135,23 @@ module ServerSideGoogleMaps
131
135
  end
132
136
 
133
137
  def calculate_distance
134
- return GeoMath.latlng_distance(*points) if @direct
138
+ return estimated_distance if @direct
135
139
  if !leg['distance']
136
140
  return leg['steps'].collect{|s| s['distance']}.collect{|d| d ? d['value'].to_i : 0}.inject(0){|s,v| s += v}
137
141
  end
138
142
  leg['distance']['value']
139
143
  end
144
+
145
+ def calculate_estimated_distance
146
+ d = 0
147
+ last_point = points[0]
148
+
149
+ points[1..-1].each do |point|
150
+ d += GeoMath.latlng_distance(last_point, point)
151
+ last_point = point
152
+ end
153
+
154
+ d
155
+ end
140
156
  end
141
157
  end
@@ -40,6 +40,10 @@ module ServerSideGoogleMaps
40
40
  @distance ||= @directionses.map{|d| d.distance}.inject(:+)
41
41
  end
42
42
 
43
+ def estimated_distance
44
+ @estimated_distance ||= @directionses.map{|d| d.estimated_distance}.inject(:+)
45
+ end
46
+
43
47
  private
44
48
 
45
49
  def calculate_points
@@ -1,3 +1,3 @@
1
1
  module ServerSideGoogleMaps
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -94,6 +94,12 @@ module ServerSideGoogleMaps
94
94
  distance.should == 199901
95
95
  end
96
96
 
97
+ it('should supply an estimated_distance') do
98
+ directions = Directions.new('Montreal,QC', 'Ottawa,ON')
99
+ distance = directions.estimated_distance
100
+ distance.should == 199127
101
+ end
102
+
97
103
  it('should suggest a straight line, with :direct') do
98
104
  directions = Directions.new('Montreal,QC', 'Ottawa,ON', :mode => :direct)
99
105
  directions.points.should == [[45.50867, -73.55368], [45.4119, -75.69846]]
data/spec/route_spec.rb CHANGED
@@ -78,6 +78,12 @@ module ServerSideGoogleMaps
78
78
  distance.should == 649742
79
79
  end
80
80
 
81
+ it('should have the proper estimated_distance') do
82
+ route = Route.new(['Montreal,QC', 'Ottawa,ON', 'Toronto,ON'])
83
+ distance = route.estimated_distance
84
+ distance.should == 647730
85
+ end
86
+
81
87
  it('should not alter params') do
82
88
  original_params = {
83
89
  :mode => :driving,
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: server-side-google-maps
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Hooper
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-01 00:00:00 -06:00
18
+ date: 2011-05-17 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency