google_api_directions 0.0.2 → 0.0.3

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: aa2713a83d0592cbad5efae3fc754321a1921d3f
4
- data.tar.gz: 97d825b53e959ef756da1914f9c0bc2c4ce446d8
3
+ metadata.gz: db184c0beee5f0f529627d2d1dfad547b4bb299c
4
+ data.tar.gz: 42663cccdbc6a6def14d58c7ad49a92a25732169
5
5
  SHA512:
6
- metadata.gz: 5c88215f5939691ca59999598fccb1065170ccadaae19a2609e22bcf9635c300d84c263ca2a162d9bc74f787522ff2f28d1c66447ef83645f106207e5f542635
7
- data.tar.gz: b9aeb11de01363c8e96e8be29ab0e6abce268bac163c5e6f70a4a7c8fb22529c3c4ce5acf4d04f7bdb718d5f8a39dfcc0dd71f23dd7c3881d2a7a6848ca25e50
6
+ metadata.gz: 34bc30fbc75423d2c9a1593cf74815ddc7682732e09ddcd0f3161b9f2fb53ef579e66302b6b88d30661549bfa6d022e6410a28c030f640f69f6a95d69bc72f3a
7
+ data.tar.gz: 46d3c6fea98290a45086aa21c2064ad9c08a37649c224a37da1dc10c3c189509cbacee61a440a07e44ed4b22ba71ca152659a0dd4fa934ec68237b7e1c986411
data/README.md CHANGED
@@ -35,12 +35,21 @@ Lets get the directions. An array of string will be returned.
35
35
 
36
36
  directions_array = result[:directions]
37
37
 
38
- How about the distance information!? A string will be returned.
38
+ Print out the directions in steps.
39
39
 
40
+ directions_array.each do |step|
41
+ #Print out Ex. {Continue forward to the end of the road, 1 km, 2 minutes
42
+ puts step.route + ", " + step.distance + ", " step.duration
43
+ end
44
+
45
+ How about the distance information (in total)!? A string will be returned.
46
+
47
+ #Ex. 7 km
40
48
  distance = result[:distance]
41
49
 
42
- And the duration of time? A string will be returned.
50
+ And the duration of time (in total)? A string will be returned.
43
51
 
52
+ #Ex. 17 minutes
44
53
  duration = result[:duration]
45
54
 
46
55
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require "rake/testtask"
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs << "test"
6
6
  t.test_files = FileList["test/**/*_test.rb"]
7
- t.verbose = true;
7
+ t.verbose = true
8
8
  end
9
9
 
10
10
  task default: :test
@@ -1,14 +1,13 @@
1
1
  require 'net/http'
2
2
  require 'open-uri'
3
3
  require 'json'
4
+ require_relative 'google_directions_route'
4
5
 
5
6
  module GoogleApiDirections
6
7
 
7
8
  class GoogleDirections
8
9
  def initialize(apikey = "")
9
- @apikey = ""
10
- @apikey = "&key=" + apikey unless apikey.empty?
11
- @uri = "http://maps.googleapis.com/maps/api/directions/json?origin="
10
+ @apikey = apikey
12
11
  @directions = []
13
12
  end
14
13
 
@@ -30,7 +29,10 @@ module GoogleApiDirections
30
29
 
31
30
  result.each do |direction|
32
31
  text = remove_html_tags(direction["html_instructions"])
33
- @directions << text.gsub(" ", " ")
32
+ route_distance = direction["distance"]["text"]
33
+ route_duration = direction["duration"]["text"]
34
+
35
+ @directions << GoogleApiDirections::GoogleDirectionsRoute.new(text.gsub(" ", " "), route_distance, route_duration)
34
36
  end
35
37
 
36
38
  {:directions => @directions, :distance => distance, :duration => duration}
@@ -42,6 +44,8 @@ module GoogleApiDirections
42
44
  end
43
45
 
44
46
  def set_uri(origin, destination, language)
47
+ @apikey = "&key=" + @apikey unless @apikey.empty?
48
+ @uri = "http://maps.googleapis.com/maps/api/directions/json?origin="
45
49
  @uri = @uri + URI::encode(origin) + "&destination=" + URI::encode(destination) + "&language=" + language + "&sensor=false" + @apikey
46
50
  end
47
51
  end
@@ -0,0 +1,17 @@
1
+ module GoogleApiDirections
2
+ class GoogleDirectionsRoute
3
+ attr_accessor :route, :distance, :duration
4
+
5
+ def initialize(route, distance, duration)
6
+ @route = route
7
+ @distance = distance
8
+ @duration = duration
9
+ end
10
+
11
+ def to_s
12
+ @route
13
+ end
14
+
15
+
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module GoogleApiDirections
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "google_api_directions/version"
2
+ require "google_api_directions/google_directions_route"
2
3
  require "google_api_directions/google_directions"
3
4
 
4
5
  module GoogleApiDirections
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_api_directions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jone Samra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-21 00:00:00.000000000 Z
11
+ date: 2014-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,6 +67,7 @@ files:
67
67
  - google_api_directions.gemspec
68
68
  - lib/google_api_directions.rb
69
69
  - lib/google_api_directions/google_directions.rb
70
+ - lib/google_api_directions/google_directions_route.rb
70
71
  - lib/google_api_directions/version.rb
71
72
  - test/google_api_directions_test.rb
72
73
  - test/test_helper.rb