distance_finder 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Guardfile +1 -0
- data/lib/distance_finder/calculator.rb +14 -7
- data/lib/distance_finder/interface.rb +1 -1
- data/lib/distance_finder/version.rb +1 -1
- 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: 3b361ceccd2ff21ea46a6ef366b16e05363d0b8e
|
4
|
+
data.tar.gz: 6f7930cef858da3d9cd2cc97d8f5fcfdedd496b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eaf183421df25673cc1b3834504ba7e66b715d5120122ddf9cd6e54ae176ae54372cfd7265e406cef925f77c7cbad3f67b00f0ad1a590836f273a9f75fa7dc0
|
7
|
+
data.tar.gz: 46f1e9165dff400595ffdebf0b9f35cbd24b7b3209e4a459443d2a037aa76fae22135ee6646a1eae52039266cee95e1fd7a15efd15c12d5075fff350cfc1e008
|
data/Guardfile
CHANGED
@@ -2,10 +2,13 @@ module DistanceFinder
|
|
2
2
|
class Calculator
|
3
3
|
|
4
4
|
attr_reader :distance, :duration, :start_address, :end_address, :display_full_response
|
5
|
+
attr_accessor :status
|
5
6
|
|
6
|
-
def initialize(origin, destination)
|
7
|
-
@origin =
|
8
|
-
@destination =
|
7
|
+
def initialize(origin, destination, mode = "driving", units = "imperial")
|
8
|
+
@origin = origin.strip()
|
9
|
+
@destination = destination.strip()
|
10
|
+
@mode = "mode=" + mode
|
11
|
+
@units = "units=" + units
|
9
12
|
@google_object = parse_response
|
10
13
|
end
|
11
14
|
|
@@ -17,7 +20,7 @@ module DistanceFinder
|
|
17
20
|
|
18
21
|
# Return distance
|
19
22
|
def distance
|
20
|
-
@google_object["routes"][0]["legs"][0]["distance"]["
|
23
|
+
@google_object["routes"][0]["legs"][0]["distance"]["text"]
|
21
24
|
end
|
22
25
|
|
23
26
|
# Return duration
|
@@ -27,11 +30,13 @@ module DistanceFinder
|
|
27
30
|
|
28
31
|
# Return origin name
|
29
32
|
def start_address
|
33
|
+
return @origin unless status == "OK"
|
30
34
|
@google_object["routes"][0]["legs"][0]["start_address"]
|
31
35
|
end
|
32
36
|
|
33
37
|
# Returns destination name
|
34
38
|
def end_address
|
39
|
+
return @destination unless status == "OK"
|
35
40
|
@google_object["routes"][0]["legs"][0]["end_address"]
|
36
41
|
end
|
37
42
|
|
@@ -62,11 +67,13 @@ module DistanceFinder
|
|
62
67
|
end
|
63
68
|
|
64
69
|
def build_url
|
65
|
-
"https://maps.googleapis.com/maps/api/directions/json?origin=#{@origin}&destination=#{@destination}"
|
70
|
+
"https://maps.googleapis.com/maps/api/directions/json?origin=#{convert_input(@origin)}&destination=#{convert_input(@destination)}&#{@units}&#{@mode}"
|
66
71
|
end
|
67
72
|
|
68
|
-
|
69
|
-
|
73
|
+
# Converts non english characters into english equivalents
|
74
|
+
# Replaces spaces with "+"
|
75
|
+
def convert_input(string)
|
76
|
+
ActiveSupport::Inflector.transliterate(string).strip().tr(" ", "+")
|
70
77
|
end
|
71
78
|
|
72
79
|
end
|
@@ -42,7 +42,7 @@ module DistanceFinder
|
|
42
42
|
if route.status == "OK"
|
43
43
|
puts format_result("⊗ Origin:", route.start_address)
|
44
44
|
puts format_result("⊗ Destination:", route.end_address)
|
45
|
-
puts format_result("⇄ Distance:", route.distance
|
45
|
+
puts format_result("⇄ Distance:", route.distance)
|
46
46
|
puts format_result("🕑 Travel time:", route.duration)
|
47
47
|
else
|
48
48
|
puts format_result("Sorry, unable to find the route.")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: distance_finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Slawomir Cieslak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|