routing 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/routing/adapter/rest_adapter.rb +8 -1
- data/lib/routing/adapter/test.rb +10 -5
- data/lib/routing/geo_point.rb +13 -1
- data/lib/routing/version.rb +1 -1
- data/spec/routing/adapter/here_spec.rb +7 -1
- data/spec/routing/adapter/navteq_spec.rb +8 -1
- data/spec/routing/adapter/test_spec.rb +8 -1
- data/spec/routing/geo_point_spec.rb +28 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0496d5dae61032467bd57c62c09305d6cb83f447
|
4
|
+
data.tar.gz: e955918eee030aa93d33382da5da4b5ae8a0372a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4b677a117f2d0983f3737bc0dc315c580348f1c1400dcf3c952f66c40da071c19c3afc0e202de32d2b8ed25609cf99631e3c109493df9ad66e41feeb8ea3577
|
7
|
+
data.tar.gz: 206a6f81707fb9e95622bc746354ecea2ff33fd1c3d8828e437ba84cb43220f505f22371597a4be163c053517fa577848287777b50ae088c24a16a43afc7f5f6
|
@@ -52,7 +52,14 @@ class Routing
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def convert_geo_points_to_params(geo_points)
|
55
|
-
Hash[geo_points.each_with_index.map
|
55
|
+
Hash[geo_points.each_with_index.map do |point, i|
|
56
|
+
lat = point[:lat]
|
57
|
+
lng = point[:lng]
|
58
|
+
|
59
|
+
raise ArgumentError, "latitude or longitude missing" unless lat && lng
|
60
|
+
|
61
|
+
["waypoint#{i}", "geo!#{lat},#{lng}"]
|
62
|
+
end]
|
56
63
|
end
|
57
64
|
end
|
58
65
|
end
|
data/lib/routing/adapter/test.rb
CHANGED
@@ -7,11 +7,16 @@ class Routing
|
|
7
7
|
|
8
8
|
def calculate(geo_points)
|
9
9
|
geo_points.collect do |point|
|
10
|
+
lat = point[:lat]
|
11
|
+
lng = point[:lng]
|
12
|
+
|
13
|
+
raise ArgumentError, "latitude or longitude missing" unless lat && lng
|
14
|
+
|
10
15
|
GeoPoint.new(
|
11
|
-
:lat =>
|
12
|
-
:lng =>
|
13
|
-
:original_lat =>
|
14
|
-
:original_lng =>
|
16
|
+
:lat => lat,
|
17
|
+
:lng => lng,
|
18
|
+
:original_lat => lat,
|
19
|
+
:original_lng => lng,
|
15
20
|
:relative_time => 100,
|
16
21
|
:distance => 100,
|
17
22
|
:waypoint => true
|
@@ -21,4 +26,4 @@ class Routing
|
|
21
26
|
end
|
22
27
|
|
23
28
|
end
|
24
|
-
end
|
29
|
+
end
|
data/lib/routing/geo_point.rb
CHANGED
@@ -30,5 +30,17 @@ class Routing
|
|
30
30
|
!!waypoint
|
31
31
|
end
|
32
32
|
|
33
|
+
def fetch(key, *args)
|
34
|
+
raise ArgumentError, "wrong number of arguments (#{args.length + 1} for 1..2)" if args.length > 1
|
35
|
+
|
36
|
+
case key
|
37
|
+
when *self.class.members
|
38
|
+
send(key)
|
39
|
+
else
|
40
|
+
return yield(key) if block_given?
|
41
|
+
return args.first unless args.empty?
|
42
|
+
raise KeyError, "key #{key} not found"
|
43
|
+
end
|
44
|
+
end
|
33
45
|
end
|
34
|
-
end
|
46
|
+
end
|
data/lib/routing/version.rb
CHANGED
@@ -16,7 +16,13 @@ describe Routing::Adapter::Here do
|
|
16
16
|
{ :parser => parser_class, :credentials => credentials}
|
17
17
|
end
|
18
18
|
|
19
|
-
let(:geo_points)
|
19
|
+
let(:geo_points) do
|
20
|
+
[
|
21
|
+
Routing::GeoPoint.new(lat: 1, lng: 2),
|
22
|
+
Routing::GeoPoint.new(lat: 3, lng: 4),
|
23
|
+
Routing::GeoPoint.new(lat: 5, lng: 6)
|
24
|
+
]
|
25
|
+
end
|
20
26
|
|
21
27
|
subject(:adapter) { described_class.new(options) }
|
22
28
|
|
@@ -11,7 +11,14 @@ describe Routing::Adapter::Navteq do
|
|
11
11
|
end
|
12
12
|
let(:parser) { double(:parser).as_null_object }
|
13
13
|
let(:options) { { host: 'example.com', parser: parser_class } }
|
14
|
-
|
14
|
+
|
15
|
+
let(:geo_points) do
|
16
|
+
[
|
17
|
+
Routing::GeoPoint.new(lat: 1, lng: 2),
|
18
|
+
Routing::GeoPoint.new(lat: 3, lng: 4),
|
19
|
+
Routing::GeoPoint.new(lat: 5, lng: 6)
|
20
|
+
]
|
21
|
+
end
|
15
22
|
|
16
23
|
subject(:adapter) { described_class.new(options) }
|
17
24
|
|
@@ -8,7 +8,14 @@ describe Routing::Adapter::Test do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '#calculate' do
|
11
|
-
let(:geo_points)
|
11
|
+
let(:geo_points) do
|
12
|
+
[
|
13
|
+
Routing::GeoPoint.new(lat: 1, lng: 2),
|
14
|
+
Routing::GeoPoint.new(lat: 3, lng: 4),
|
15
|
+
Routing::GeoPoint.new(lat: 5, lng: 6)
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
12
19
|
|
13
20
|
it 'returns an array of geopoints with values that are passed to the method' do
|
14
21
|
subject.calculate(geo_points).each_with_index do |new_geo_point, index|
|
@@ -1,28 +1,47 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Routing::GeoPoint do
|
4
|
-
|
5
4
|
context 'creating a new instance' do
|
6
5
|
it 'can be instantiated without arguments' do
|
7
6
|
expect { described_class.new }.to_not raise_error
|
8
7
|
end
|
9
8
|
|
9
|
+
describe '#fetch' do
|
10
|
+
subject(:geo_point) { described_class.new }
|
11
|
+
|
12
|
+
it 'raises if the key is not a struct member and no default has been specified' do
|
13
|
+
expect { geo_point.fetch(:unknown) }.to raise_error(KeyError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns the second argument or the return value of an optional block when #fetch is invoked with a key that is not a struct member (the block has precedence)' do
|
17
|
+
expect(geo_point.fetch(:unknown, 42)).to eq(42)
|
18
|
+
expect(geo_point.fetch(:unknown, 42) { 13 }).to eq(13)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
10
22
|
context 'initialized with attributes' do
|
11
|
-
subject { described_class.new(:lat => 1, :lng => 2) }
|
23
|
+
subject(:geo_point) { described_class.new(:lat => 1, :lng => 2) }
|
12
24
|
|
13
|
-
|
14
|
-
|
15
|
-
it { should be(1) }
|
25
|
+
it "should respond with 1 when #lat is invoked" do
|
26
|
+
expect(geo_point.lat).to eq(1)
|
16
27
|
end
|
17
28
|
|
18
|
-
|
19
|
-
|
20
|
-
|
29
|
+
it "should respond with 1 when #fetch(:lat) is invoked" do
|
30
|
+
expect(geo_point.fetch(:lat)).to eq(1)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should respond with 2 when #lng is invoked" do
|
34
|
+
expect(geo_point.lng).to eq(2)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should respond with 2 when #fetch(:lng) is invoked" do
|
38
|
+
expect(geo_point.fetch(:lng)).to eq(2)
|
21
39
|
end
|
22
40
|
|
23
41
|
it 'ignores passed attributes that dont exist' do
|
24
42
|
expect { described_class.new(:hello => :world) }.to_not raise_error
|
25
43
|
end
|
44
|
+
|
26
45
|
end
|
27
46
|
end
|
28
47
|
|
@@ -43,5 +62,4 @@ describe Routing::GeoPoint do
|
|
43
62
|
it { should_not be_waypoint }
|
44
63
|
end
|
45
64
|
end
|
46
|
-
|
47
|
-
end
|
65
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: routing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Bäuerlein
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-08-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|