google-maps 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.mkd +1 -1
- data/lib/google-maps.rb +16 -10
- data/lib/google-maps/route.rb +12 -11
- data/lib/google-maps/version.rb +1 -1
- data/spec/google-maps/route_spec.rb +9 -9
- 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: 13f8b08401429d693bf7b68fc78d5f215be09eb0
|
4
|
+
data.tar.gz: 001d41179c93c787757a42cfce0b1738aa267673
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 924bdce3f76819f03c4f2f51618a692874efb12cc69d77d6d2ae038d1d9b825cf1bdb53a746ed21eaca6921ca2a78d30311f64895c41461a9643f3b218acdf9e
|
7
|
+
data.tar.gz: 16b04aebffcac817ee1c7d298110f0433718ce0ed3c54bf43a557bb1d45352bdac83cee720b44456ea4754aa4d17ea329e747edad7dfc554560f433610c85895
|
data/README.mkd
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/zilverline/google-maps.svg?branch=master)](https://travis-ci.org/zilverline/google-maps)
|
2
|
-
[![Coverage Status](https://coveralls.io/repos/zilverline/google-maps/badge.svg)](https://coveralls.io/r/zilverline/google-maps)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/zilverline/google-maps/badge.svg?branch=master)](https://coveralls.io/r/zilverline/google-maps?branch=master)
|
3
3
|
[![Code Climate](https://codeclimate.com/repos/55671579695680044d01e0ac/badges/8f4d88f30585847e4fcf/gpa.svg)](https://codeclimate.com/repos/55671579695680044d01e0ac/feed)
|
4
4
|
|
5
5
|
Google Maps
|
data/lib/google-maps.rb
CHANGED
@@ -8,19 +8,19 @@ module Google
|
|
8
8
|
module Maps
|
9
9
|
extend Configuration
|
10
10
|
extend Logger
|
11
|
-
|
12
|
-
def self.route(from, to,
|
13
|
-
Route.new(from, to,
|
11
|
+
|
12
|
+
def self.route(from, to, options={})
|
13
|
+
Route.new(from, to, options_with_defaults(options))
|
14
14
|
end
|
15
|
-
|
16
|
-
def self.distance(from, to,
|
17
|
-
Route.new(from, to,
|
15
|
+
|
16
|
+
def self.distance(from, to, options={})
|
17
|
+
Route.new(from, to, options_with_defaults(options)).distance.text
|
18
18
|
end
|
19
|
-
|
20
|
-
def self.duration(from, to,
|
21
|
-
Route.new(from, to,
|
19
|
+
|
20
|
+
def self.duration(from, to, options={})
|
21
|
+
Route.new(from, to, options_with_defaults(options)).duration.text
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def self.places(keyword, language = self.default_language)
|
25
25
|
Place.find(keyword, language)
|
26
26
|
end
|
@@ -34,5 +34,11 @@ module Google
|
|
34
34
|
rescue ZeroResultsException
|
35
35
|
[]
|
36
36
|
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def self.options_with_defaults(options)
|
41
|
+
{language: self.default_language}.merge(options)
|
42
|
+
end
|
37
43
|
end
|
38
44
|
end
|
data/lib/google-maps/route.rb
CHANGED
@@ -2,12 +2,13 @@ require File.expand_path('../api', __FILE__)
|
|
2
2
|
|
3
3
|
module Google
|
4
4
|
module Maps
|
5
|
-
|
5
|
+
|
6
6
|
class Route
|
7
|
-
attr_accessor :from, :to, :
|
8
|
-
|
9
|
-
def initialize(from, to,
|
10
|
-
|
7
|
+
attr_accessor :from, :to, :options
|
8
|
+
|
9
|
+
def initialize(from, to, options={})
|
10
|
+
options = {language: options} unless options.is_a? Hash
|
11
|
+
@from, @to, @options = from, to, {language: :en}.merge(options)
|
11
12
|
end
|
12
13
|
|
13
14
|
def method_missing(name, *args, &block)
|
@@ -17,21 +18,21 @@ module Google
|
|
17
18
|
super
|
18
19
|
end
|
19
20
|
end
|
20
|
-
|
21
|
+
|
21
22
|
def origin_latlong
|
22
23
|
"#{self.start_location.lat},#{self.start_location.lng}"
|
23
24
|
end
|
24
|
-
|
25
|
+
|
25
26
|
def destination_latlong
|
26
27
|
"#{self.end_location.lat},#{self.end_location.lng}"
|
27
28
|
end
|
28
|
-
|
29
|
+
|
29
30
|
private
|
30
31
|
def route
|
31
32
|
# default to the first returned route (the most efficient one)
|
32
|
-
@response ||= API.query(:directions_service, :
|
33
|
+
@response ||= API.query(:directions_service, @options.merge(origin: from, destination: to)).routes.first
|
33
34
|
end
|
34
35
|
end
|
35
|
-
|
36
|
+
|
36
37
|
end
|
37
|
-
end
|
38
|
+
end
|
data/lib/google-maps/version.rb
CHANGED
@@ -6,47 +6,47 @@ describe Google::Maps::Route do
|
|
6
6
|
stub_response("amsterdam-deventer-nl.json")
|
7
7
|
@route = Google::Maps::Route.new("Science Park, Amsterdam", "Deventer", :nl)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should be able to calculate a route" do
|
11
11
|
@route.distance.text.should == "104 km"
|
12
12
|
@route.duration.text.should == "1 uur 12 min."
|
13
13
|
@route.distance.value.should == 103712
|
14
14
|
@route.duration.value.should == 4337
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "should be able to present the text in Dutch" do
|
18
|
-
@route.language.should == :nl
|
18
|
+
@route.options[:language].should == :nl
|
19
19
|
@route.end_address.should == "Deventer, Nederland"
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should be able to return the address for the origin" do
|
23
23
|
@route.start_address.should == "Science Park, 1098 Amsterdam, Nederland"
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should be able to return the address for the destination" do
|
27
27
|
@route.end_address.should == "Deventer, Nederland"
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "should be able to return the latiude and longitude for the origin" do
|
31
31
|
@route.start_location.lat.should == 52.35445000000001
|
32
32
|
@route.start_location.lng.should == 4.95420
|
33
33
|
@route.origin_latlong.should == "52.35445000000001,4.9542"
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should be able to return the latiude and longitude for the destination" do
|
37
37
|
@route.end_location.lat.should == 52.25441000000001
|
38
38
|
@route.end_location.lng.should == 6.160470
|
39
39
|
@route.destination_latlong.should == "52.25441000000001,6.16047"
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
describe "english" do
|
44
44
|
it "should be able to present the text in English" do
|
45
45
|
stub_response("amsterdam-deventer-en.json")
|
46
46
|
route = Google::Maps::Route.new("Science Park, Amsterdam", "Deventer", :en)
|
47
|
-
route.language.should == :en
|
47
|
+
route.options[:language].should == :en
|
48
48
|
route.end_address.should == "Deventer, The Netherlands"
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-maps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel van Hoesel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|