google_distance_matrix 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/lib/google_distance_matrix/place.rb +4 -0
- data/lib/google_distance_matrix/routes_finder.rb +2 -0
- data/lib/google_distance_matrix/version.rb +1 -1
- data/spec/lib/google_distance_matrix/place_spec.rb +8 -0
- data/spec/lib/google_distance_matrix/routes_finder_spec.rb +30 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d95262e2f29c248bbf1d42d16d95b9148ef0d16354a4e4dc8e4f5af23364980
|
4
|
+
data.tar.gz: 8911ea692148753e4325908ae0c3b6dffa2c08fbcef4b0585afe5d4f2e45f10d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9149df909c7604f327b4d342d34e3df99c5898e109a434ef30a123e848cd5591ab01d51d921460907ba53b3a31deccd5ad484fe89e7027aafdbb7a3309eb7ac8
|
7
|
+
data.tar.gz: c8c1054b9060e0ecec7648313931f1d3349ec24cd74ce2f0ffec14cc893c7eda47654cd6df2422b1b162d51c57d1e92222f568d4c9ba25a0d67ff554b9f1aaa5
|
data/CHANGELOG.md
CHANGED
@@ -22,6 +22,7 @@ module GoogleDistanceMatrix
|
|
22
22
|
if respond_to_needed_attributes? attributes_or_object
|
23
23
|
extract_and_assign_attributes_from_object attributes_or_object
|
24
24
|
elsif attributes_or_object.is_a? Hash
|
25
|
+
@extracted_attributes_from = attributes_or_object.with_indifferent_access
|
25
26
|
assign_attributes attributes_or_object
|
26
27
|
else
|
27
28
|
raise ArgumentError, 'Must be either hash or object responding to lat, lng or address. '
|
@@ -36,12 +37,15 @@ module GoogleDistanceMatrix
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def eql?(other)
|
40
|
+
return false unless other.is_a? self.class
|
41
|
+
|
39
42
|
if address.present?
|
40
43
|
address == other.address
|
41
44
|
else
|
42
45
|
lat_lng == other.lat_lng
|
43
46
|
end
|
44
47
|
end
|
48
|
+
alias == eql?
|
45
49
|
|
46
50
|
def lat_lng?
|
47
51
|
lat.present? && lng.present?
|
@@ -95,4 +95,12 @@ describe GoogleDistanceMatrix::Place do
|
|
95
95
|
.to_not be_eql described_class.new(lat: lat, lng: lng + 1)
|
96
96
|
end
|
97
97
|
end
|
98
|
+
|
99
|
+
describe '#==' do
|
100
|
+
it 'is considered equal when places are compared with ==' do
|
101
|
+
expect(described_class.new(address: address) ==
|
102
|
+
GoogleDistanceMatrix::Place.new(address: address))
|
103
|
+
.to be_truthy
|
104
|
+
end
|
105
|
+
end
|
98
106
|
end
|
@@ -3,7 +3,8 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
6
|
-
let(:
|
6
|
+
let(:origin_1_attributes) { { address: 'Karl Johans gate, Oslo' } }
|
7
|
+
let(:origin_1) { GoogleDistanceMatrix::Place.new origin_1_attributes }
|
7
8
|
let(:origin_2) { GoogleDistanceMatrix::Place.new address: 'Askerveien 1, Asker' }
|
8
9
|
|
9
10
|
let(:destination_1) { GoogleDistanceMatrix::Place.new address: 'Drammensveien 1, Oslo' }
|
@@ -70,6 +71,13 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
|
70
71
|
expect(routes.map(&:origin).all? { |o| o == origin_1 }).to be true
|
71
72
|
end
|
72
73
|
|
74
|
+
it 'still returns routes for origin if it has same address but different object_id' do
|
75
|
+
routes = subject.routes_for GoogleDistanceMatrix::Place.new origin_1_attributes
|
76
|
+
|
77
|
+
expect(routes.length).to eq 2
|
78
|
+
expect(routes.map(&:origin).all? { |o| o == origin_1 }).to be true
|
79
|
+
end
|
80
|
+
|
73
81
|
it 'returns routes for given destination' do
|
74
82
|
routes = subject.routes_for destination_2
|
75
83
|
|
@@ -83,6 +91,17 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
|
83
91
|
expect(routes.length).to eq 2
|
84
92
|
expect(routes.map(&:destination).all? { |d| d == destination_2 }).to be true
|
85
93
|
end
|
94
|
+
|
95
|
+
context 'place built from hash' do
|
96
|
+
let(:destination_2_built_from) { { address: 'Skjellestadhagen, Heggedal' } }
|
97
|
+
|
98
|
+
it 'returns routes for given hash a place was built from' do
|
99
|
+
routes = subject.routes_for destination_2_built_from
|
100
|
+
|
101
|
+
expect(routes.length).to eq 2
|
102
|
+
expect(routes.map(&:destination).all? { |d| d == destination_2 }).to be true
|
103
|
+
end
|
104
|
+
end
|
86
105
|
end
|
87
106
|
|
88
107
|
describe '#routes_for!' do
|
@@ -104,6 +123,16 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
|
104
123
|
expect(route.destination).to eq destination_2
|
105
124
|
end
|
106
125
|
|
126
|
+
context 'place built from hash' do
|
127
|
+
let(:destination_2_built_from) { { address: 'Skjellestadhagen, Heggedal' } }
|
128
|
+
|
129
|
+
it 'returns route when you give it the hash the place was built from' do
|
130
|
+
route = subject.route_for(origin: origin_1, destination: destination_2_built_from)
|
131
|
+
expect(route.origin).to eq origin_1
|
132
|
+
expect(route.destination).to eq destination_2
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
107
136
|
it 'fails with argument error if origin is missing' do
|
108
137
|
expect { subject.route_for destination: destination_2 }.to raise_error ArgumentError
|
109
138
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_distance_matrix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thorbjørn Hermansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|