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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87ff87fa819023f3a7df1755f6ea105407153493
4
- data.tar.gz: 58405c0061e23763bf2c413ecb1c3a49fb9217c5
3
+ metadata.gz: 3b361ceccd2ff21ea46a6ef366b16e05363d0b8e
4
+ data.tar.gz: 6f7930cef858da3d9cd2cc97d8f5fcfdedd496b0
5
5
  SHA512:
6
- metadata.gz: 0b8303f7579e002366f355e59b052f3302ab3450e5aa7efa2ffff08d785b7aa17b26a4e2168ddbc6f2aaaebf8bee503eb840b58dfb71af4087a19f80403b7db4
7
- data.tar.gz: 764b47fe6f8c5f4eaa3f6bc3da8bf689e83992ae6fefd7335882f01e516ec948b64d7c0e6e08bbc685eae26a1989d5f87c2e8a35898a22dc6b1e8126f784825a
6
+ metadata.gz: 4eaf183421df25673cc1b3834504ba7e66b715d5120122ddf9cd6e54ae176ae54372cfd7265e406cef925f77c7cbad3f67b00f0ad1a590836f273a9f75fa7dc0
7
+ data.tar.gz: 46f1e9165dff400595ffdebf0b9f35cbd24b7b3209e4a459443d2a037aa76fae22135ee6646a1eae52039266cee95e1fd7a15efd15c12d5075fff350cfc1e008
data/Guardfile CHANGED
@@ -21,4 +21,5 @@ guard :minitest do
21
21
  watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
22
22
  watch(%r{^test/test_helper\.rb$}) { 'test' }
23
23
  watch(%r{^test/(.+)_test\.rb$}) { 'test' }
24
+ watch(%r{^lib/(.*)}) { 'test' }
24
25
  end
@@ -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 = strip_input(origin)
8
- @destination = strip_input(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"]["value"] / 1000 * 0.621371
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
- def strip_input(string)
69
- ActiveSupport::Inflector.transliterate(string).strip()
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.round(1).to_s + " miles")
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.")
@@ -1,3 +1,3 @@
1
1
  module DistanceFinder
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
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.3
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-20 00:00:00.000000000 Z
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport