geogle 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/geogle/model/route.rb +12 -1
- data/lib/geogle/version.rb +1 -1
- data/spec/geogle/model/route_spec.rb +72 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59971ca7418221740357fa9b594dde42d03440b6
|
4
|
+
data.tar.gz: 345ab8e0bd5f5f8ccda3e5c58a7cd3aec330b10d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60083cda7c20d3e9cf12ac71eb6d28eea17045ca286dcd4fc2625531c5dc96c8717087eca525d3aafbb5945049178b7aa9f6fc5dd98966eadd2f4afd3e4056a1
|
7
|
+
data.tar.gz: 78018940b80d0b98925bfdd28bf8b96836372c2b5c182154b388d5c3bc6d6c863bed359cd626c6a0bd68de09845d0536b7497481bd406f602f861c6e8093bfcc
|
data/lib/geogle/model/route.rb
CHANGED
@@ -18,26 +18,37 @@ module Geogle
|
|
18
18
|
attribute :copyrights, String
|
19
19
|
attribute :warnings, Array[String]
|
20
20
|
|
21
|
+
# Total duration
|
21
22
|
def duration
|
22
23
|
sum_values(legs.map(&:duration))
|
23
24
|
end
|
24
25
|
|
26
|
+
# Total distance
|
25
27
|
def distance
|
26
28
|
sum_values(legs.map(&:distance))
|
27
29
|
end
|
28
30
|
|
31
|
+
# Name of starting address
|
29
32
|
def origin
|
30
33
|
legs.first.start_address
|
31
34
|
end
|
32
35
|
|
36
|
+
# Name of destination address
|
33
37
|
def destination
|
34
38
|
legs.last.end_address
|
35
39
|
end
|
36
40
|
|
41
|
+
# Array of points that represents the entire path
|
42
|
+
def path
|
43
|
+
coordinates = legs.map(&:steps).flatten.map(&:start_location)
|
44
|
+
coordinates << legs.last.steps.last.end_location
|
45
|
+
coordinates
|
46
|
+
end
|
47
|
+
|
37
48
|
private
|
38
49
|
|
39
50
|
def sum_values(values)
|
40
|
-
values.map(&:value).inject(:+)
|
51
|
+
values.map(&:value).inject(:+)
|
41
52
|
end
|
42
53
|
end
|
43
54
|
end
|
data/lib/geogle/version.rb
CHANGED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Geogle::Model
|
2
|
+
describe Route do
|
3
|
+
def text_value(value)
|
4
|
+
TextValue.new(value: value)
|
5
|
+
end
|
6
|
+
|
7
|
+
def step(start_location, end_location)
|
8
|
+
Step.new(
|
9
|
+
start_location: start_location,
|
10
|
+
end_location: end_location
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def coordinates(lat, lng)
|
15
|
+
Coordinates.new(lat: lat, lng: lng)
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:step1) { step(coordinates(51, 20), coordinates(52, 20)) }
|
19
|
+
let(:step2) { step(coordinates(52, 21), coordinates(53, 21)) }
|
20
|
+
let(:step3) { step(coordinates(53, 21), coordinates(53, 22)) }
|
21
|
+
let(:step4) { step(coordinates(53, 22), coordinates(54, 22)) }
|
22
|
+
|
23
|
+
let(:leg1) do
|
24
|
+
Leg.new(
|
25
|
+
duration: text_value(10),
|
26
|
+
distance: text_value(20),
|
27
|
+
start_address: "Earth",
|
28
|
+
steps: [step1, step2]
|
29
|
+
)
|
30
|
+
end
|
31
|
+
let(:leg2) do
|
32
|
+
Leg.new(
|
33
|
+
duration: text_value(20),
|
34
|
+
distance: text_value(30),
|
35
|
+
end_address: "Moon",
|
36
|
+
steps: [step3, step4]
|
37
|
+
)
|
38
|
+
end
|
39
|
+
let(:legs) { [leg1, leg2] }
|
40
|
+
let(:route) { described_class.new(legs: legs)}
|
41
|
+
|
42
|
+
it "duration adds the durations of all legs" do
|
43
|
+
expect(route.duration).to eq(30)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "distance adds the distances of all legs" do
|
47
|
+
expect(route.distance).to eq(50)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "origin returns the start_address of the first leg" do
|
51
|
+
expect(route.origin).to eq("Earth")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "destination returns the end_address of the last leg" do
|
55
|
+
expect(route.destination).to eq("Moon")
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "path" do
|
59
|
+
it "there's one more point than steps exists" do
|
60
|
+
expect(route.path.count).to eq(5)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "the origin point matches with start_location of the first step" do
|
64
|
+
expect(route.path.first).to eq(step1.start_location)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "the destination point with the end_location of the last step" do
|
68
|
+
expect(route.path.last).to eq(step4.end_location)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geogle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yone_lc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- spec/geogle/directions_spec.rb
|
185
185
|
- spec/geogle/geocoder_spec.rb
|
186
186
|
- spec/geogle/model/leg_spec.rb
|
187
|
+
- spec/geogle/model/route_spec.rb
|
187
188
|
- spec/geogle/parser_spec.rb
|
188
189
|
- spec/geogle/url_builder_spec.rb
|
189
190
|
- spec/spec_helper.rb
|
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
209
|
version: '0'
|
209
210
|
requirements: []
|
210
211
|
rubyforge_project:
|
211
|
-
rubygems_version: 2.4.
|
212
|
+
rubygems_version: 2.4.2
|
212
213
|
signing_key:
|
213
214
|
specification_version: 4
|
214
215
|
summary: Provides a Ruby interface to geocode requests to Google Maps API V3 and parse
|
@@ -225,6 +226,7 @@ test_files:
|
|
225
226
|
- spec/geogle/directions_spec.rb
|
226
227
|
- spec/geogle/geocoder_spec.rb
|
227
228
|
- spec/geogle/model/leg_spec.rb
|
229
|
+
- spec/geogle/model/route_spec.rb
|
228
230
|
- spec/geogle/parser_spec.rb
|
229
231
|
- spec/geogle/url_builder_spec.rb
|
230
232
|
- spec/spec_helper.rb
|