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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a49e29dbffb57a00e02111ebb486d6ef57c48d9
4
- data.tar.gz: 0a4104acf4545f919bee3a4c7b22cdc8eb14076b
3
+ metadata.gz: 0496d5dae61032467bd57c62c09305d6cb83f447
4
+ data.tar.gz: e955918eee030aa93d33382da5da4b5ae8a0372a
5
5
  SHA512:
6
- metadata.gz: 10aa9dc049fe739036ce6149ec156735179a51bb8a33cb72ea2902d5a55d530402e40e35011801bfd631e104690b1022a3c1a9ca28fbda23199e82f5b32b331d
7
- data.tar.gz: 98ebd1ea41a04d78d9aa8712fd2503bead5fd27640387a5fd54640e5d68d016d188906d4b74e7e278f153f9de0cfe5e6c7ef1ad03800a0e2f60e90584e456424
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 { |point, i| [ "waypoint#{i}", "geo!#{point.lat},#{point.lng}" ] }]
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
@@ -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 => point.lat,
12
- :lng => point.lng,
13
- :original_lat => point.lat,
14
- :original_lng => point.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
@@ -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
@@ -1,3 +1,3 @@
1
1
  class Routing
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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) { [double(:lat => 1, :lng => 2), double(:lat => 3, :lng => 4), double(:lat => 5, :lng => 6)] }
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
- let(:geo_points) { [double(lat: 1, lng: 2), double(lat: 3, lng: 4), double(lat: 5, lng: 6)] }
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) { [double(lat: 1, lng: 2), double(lat: 3, lng: 4), double(lat: 5, lng: 6)] }
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
- describe '#lat' do
14
- subject { super().lat }
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
- describe '#lng' do
19
- subject { super().lng }
20
- it { should be(2) }
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.1.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-07-23 00:00:00.000000000 Z
12
+ date: 2014-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday