go_maps 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,6 +1,13 @@
1
1
  ## ABOUT
2
2
 
3
- Easy way to get the distance between two addresses (by car)
3
+ Ruby API to geographic operations. Currently it supports the validation of an address and the distance between two of them.
4
+
5
+ ## USAGE
6
+
7
+ address = Address.new "Rua Tenerife, 31, Sao Paulo, Brasil"
8
+ address.exists?
9
+ address.distance_to "Av Paulista, Sao Paulo, Brasil"
10
+ GoMaps::Direction.new(:from => "Av Paulista 100, Sao Paulo, Brasil", :to => "Avenida Brigadeiro Faria Lima 1000, Sao Paulo, Brasil").to_map
4
11
 
5
12
  ## LICENSE
6
13
 
data/Rakefile CHANGED
@@ -1,11 +1,13 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
+ ENV['RSPEC_COLOR'] = 'true'
5
+
4
6
  begin
5
7
  require 'jeweler'
6
8
  Jeweler::Tasks.new do |gem|
7
9
  gem.name = "go_maps"
8
- gem.version = "0.1.0"
10
+ gem.version = "0.2.0"
9
11
  gem.summary = %Q{Ruby API to geographic operations}
10
12
  gem.description = %Q{Ruby API to geographic operations}
11
13
  gem.homepage = "http://github.com/gonow/go_maps"
data/go_maps.gemspec ADDED
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{go_maps}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Gonow"]
12
+ s.date = %q{2010-07-13}
13
+ s.description = %q{Ruby API to geographic operations}
14
+ s.extra_rdoc_files = [
15
+ "README.markdown"
16
+ ]
17
+ s.files = [
18
+ ".gitignore",
19
+ "README.markdown",
20
+ "Rakefile",
21
+ "go_maps.gemspec",
22
+ "lib/go_maps.rb",
23
+ "lib/go_maps/address.rb",
24
+ "lib/go_maps/address_not_found_exception.rb",
25
+ "lib/go_maps/direction.rb",
26
+ "spec/data/address_error",
27
+ "spec/data/address_success",
28
+ "spec/data/distance_error",
29
+ "spec/data/distance_success_10.8",
30
+ "spec/go_maps/address_spec.rb",
31
+ "spec/go_maps/direction_spec.rb",
32
+ "spec/spec.opts",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/gonow/go_maps}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.6}
39
+ s.summary = %q{Ruby API to geographic operations}
40
+ s.test_files = [
41
+ "spec/go_maps/address_spec.rb",
42
+ "spec/go_maps/direction_spec.rb",
43
+ "spec/spec_helper.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
52
+ s.add_development_dependency(%q<fakeweb>, [">= 1.2.8"])
53
+ s.add_runtime_dependency(%q<crack>, [">= 0.1.6"])
54
+ else
55
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
+ s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
57
+ s.add_dependency(%q<crack>, [">= 0.1.6"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
61
+ s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
62
+ s.add_dependency(%q<crack>, [">= 0.1.6"])
63
+ end
64
+ end
65
+
data/lib/go_maps.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'crack'
2
2
  require 'open-uri'
3
- require 'go_maps/address'
4
- require 'go_maps/address_not_found_exception'
3
+
4
+ Dir.glob(File.dirname(__FILE__) + '/go_maps/*.rb').each { |file| require file }
5
+
@@ -9,7 +9,7 @@ module GoMaps
9
9
  end
10
10
 
11
11
  def distance_to(address)
12
- directions_to(address)['routes'].first['legs'].first['distance']['text'].gsub(' km', '').gsub(',', '.').to_f rescue raise AddressNotFoundException
12
+ directions_to(address)['routes'].first['legs'].first['distance']['text'].to_f rescue raise AddressNotFoundException
13
13
  end
14
14
 
15
15
  private
@@ -27,7 +27,7 @@ module GoMaps
27
27
  end
28
28
 
29
29
  def url_for(api)
30
- "http://maps.google.com/maps/api/#{api}/json?sensor=false&language=pt-BR&"
30
+ "http://maps.google.com/maps/api/#{api}/json?sensor=false&units=metric&"
31
31
  end
32
32
  end
33
33
  end
@@ -0,0 +1,21 @@
1
+ module GoMaps
2
+ class Direction
3
+ def initialize(params)
4
+ @from = params[:from]
5
+ @to = params[:to]
6
+ end
7
+
8
+ def to_map(options = {})
9
+ width = options[:width] || 425
10
+ height = options[:height] || 350
11
+ "<iframe width='#{width}' height='#{height}' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='#{map_url(@from, @to)}'></iframe>"
12
+ end
13
+
14
+ private
15
+
16
+ def map_url(origin, destination)
17
+ "http://maps.google.com/maps?ie=UTF8&output=embed&saddr=#{origin}&daddr=#{destination}"
18
+ end
19
+ end
20
+ end
21
+
@@ -47,7 +47,7 @@
47
47
  "html_instructions": "Pegue a primeira \u003cb\u003eà esquerda\u003c/b\u003e para pegar a \u003cb\u003eAv. Dr. Cardoso de Melo\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e600&nbsp;m\u003c/b\u003e\u003c/span\u003e",
48
48
  "distance": {
49
49
  "value": 615,
50
- "text": "0,6 km"
50
+ "text": "0.6 km"
51
51
  }
52
52
  }, {
53
53
  "travel_mode": "DRIVING",
@@ -70,7 +70,7 @@
70
70
  "html_instructions": "Vire à \u003cb\u003edireita\u003c/b\u003e na \u003cb\u003eR. Alvorada\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e110&nbsp;m\u003c/b\u003e\u003c/span\u003e",
71
71
  "distance": {
72
72
  "value": 105,
73
- "text": "0,1 km"
73
+ "text": "0.1 km"
74
74
  }
75
75
  }, {
76
76
  "travel_mode": "DRIVING",
@@ -93,7 +93,7 @@
93
93
  "html_instructions": "Continue para \u003cb\u003eR. Dr. Manuel da Rocha Passos Filho\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e140&nbsp;m\u003c/b\u003e\u003c/span\u003e",
94
94
  "distance": {
95
95
  "value": 137,
96
- "text": "0,1 km"
96
+ "text": "0.1 km"
97
97
  }
98
98
  }, {
99
99
  "travel_mode": "DRIVING",
@@ -116,7 +116,7 @@
116
116
  "html_instructions": "Vire à \u003cb\u003eesquerda\u003c/b\u003e na \u003cb\u003eAv. dos Bandeirantes\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e450&nbsp;m\u003c/b\u003e\u003c/span\u003e",
117
117
  "distance": {
118
118
  "value": 431,
119
- "text": "0,4 km"
119
+ "text": "0.4 km"
120
120
  }
121
121
  }, {
122
122
  "travel_mode": "DRIVING",
@@ -139,7 +139,7 @@
139
139
  "html_instructions": "Curva suave à \u003cb\u003edireita\u003c/b\u003e na \u003cb\u003eAv. dos Bandeirantes-pista Central\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e600&nbsp;m\u003c/b\u003e\u003c/span\u003e",
140
140
  "distance": {
141
141
  "value": 588,
142
- "text": "0,6 km"
142
+ "text": "0.6 km"
143
143
  }
144
144
  }, {
145
145
  "travel_mode": "DRIVING",
@@ -162,7 +162,7 @@
162
162
  "html_instructions": "Continue para \u003cb\u003eAv. dos Bandeirantes\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e2,0&nbsp;km\u003c/b\u003e\u003c/span\u003e",
163
163
  "distance": {
164
164
  "value": 1957,
165
- "text": "2,0 km"
165
+ "text": "2.0 km"
166
166
  }
167
167
  }, {
168
168
  "travel_mode": "DRIVING",
@@ -185,7 +185,7 @@
185
185
  "html_instructions": "Pegue a saída em direção a \u003cb\u003eVd. João Julião da Costa Aguiar\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e280&nbsp;m\u003c/b\u003e\u003c/span\u003e",
186
186
  "distance": {
187
187
  "value": 284,
188
- "text": "0,3 km"
188
+ "text": "0.3 km"
189
189
  }
190
190
  }, {
191
191
  "travel_mode": "DRIVING",
@@ -208,7 +208,7 @@
208
208
  "html_instructions": "Vire à \u003cb\u003edireita\u003c/b\u003e na \u003cb\u003eVd. João Julião da Costa Aguiar\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e280&nbsp;m\u003c/b\u003e\u003c/span\u003e",
209
209
  "distance": {
210
210
  "value": 284,
211
- "text": "0,3 km"
211
+ "text": "0.3 km"
212
212
  }
213
213
  }, {
214
214
  "travel_mode": "DRIVING",
@@ -231,7 +231,7 @@
231
231
  "html_instructions": "Continue para \u003cb\u003eAv. Moreira Guimarães\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e1,2&nbsp;km\u003c/b\u003e\u003c/span\u003e",
232
232
  "distance": {
233
233
  "value": 1179,
234
- "text": "1,2 km"
234
+ "text": "1.2 km"
235
235
  }
236
236
  }, {
237
237
  "travel_mode": "DRIVING",
@@ -254,7 +254,7 @@
254
254
  "html_instructions": "Continue para \u003cb\u003eAv. Rubem Berta\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e1,9&nbsp;km\u003c/b\u003e\u003c/span\u003e",
255
255
  "distance": {
256
256
  "value": 1917,
257
- "text": "1,9 km"
257
+ "text": "1.9 km"
258
258
  }
259
259
  }, {
260
260
  "travel_mode": "DRIVING",
@@ -277,7 +277,7 @@
277
277
  "html_instructions": "Continue para \u003cb\u003eAv. Vinte e Três de Maio\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e1,7&nbsp;km\u003c/b\u003e\u003c/span\u003e",
278
278
  "distance": {
279
279
  "value": 1747,
280
- "text": "1,7 km"
280
+ "text": "1.7 km"
281
281
  }
282
282
  }, {
283
283
  "travel_mode": "DRIVING",
@@ -323,7 +323,7 @@
323
323
  "html_instructions": "Continue para \u003cb\u003eR. Estela\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e550&nbsp;m\u003c/b\u003e\u003c/span\u003e",
324
324
  "distance": {
325
325
  "value": 536,
326
- "text": "0,5 km"
326
+ "text": "0.5 km"
327
327
  }
328
328
  }, {
329
329
  "travel_mode": "DRIVING",
@@ -369,7 +369,7 @@
369
369
  "html_instructions": "Continue para \u003cb\u003eAv. Bernardino de Campos/Vd. Santa Generosa\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e650&nbsp;m\u003c/b\u003e\u003c/span\u003e\u003cdiv style=\"font-size:0.9em\"\u003eContinue na Av. Bernardino de Campos\u003c/div\u003e",
370
370
  "distance": {
371
371
  "value": 666,
372
- "text": "0,7 km"
372
+ "text": "0.7 km"
373
373
  }
374
374
  }, {
375
375
  "travel_mode": "DRIVING",
@@ -392,7 +392,7 @@
392
392
  "html_instructions": "Continue para \u003cb\u003eAv. Paulista\u003c/b\u003e \u003cspan style=\"white-space: nowrap\"\u003e- siga \u003cb\u003e100&nbsp;m\u003c/b\u003e\u003c/span\u003e\u003cdiv style=\"font-size:0.9em\"\u003eO destino estará à direita\u003c/div\u003e",
393
393
  "distance": {
394
394
  "value": 103,
395
- "text": "0,1 km"
395
+ "text": "0.1 km"
396
396
  }
397
397
  } ],
398
398
  "duration": {
@@ -401,7 +401,7 @@
401
401
  },
402
402
  "distance": {
403
403
  "value": 10774,
404
- "text": "10,8 km"
404
+ "text": "10.8 km"
405
405
  },
406
406
  "start_location": {
407
407
  "lat": -23.5962400,
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe GoMaps::Direction do
4
+ context 'on #to_map' do
5
+ before :each do
6
+ @address1, @address2 = 'Invalid Address 1', 'Invalid Address 2'
7
+ end
8
+
9
+ it 'should return a map' do
10
+ GoMaps::Direction.new(:from => @address1, :to => @address2).to_map.should eql("<iframe width='425' height='350' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps?ie=UTF8&output=embed&saddr=#{@address1}&daddr=#{@address2}'></iframe>")
11
+ end
12
+
13
+ it 'should accept width as an option' do
14
+ GoMaps::Direction.new(:from => @address1, :to => @address2).to_map(:width => 333).include?('width=\'333\'').should be_true
15
+ end
16
+
17
+ it 'should accept height as an option' do
18
+ GoMaps::Direction.new(:from => @address1, :to => @address2).to_map(:height => 444).include?('height=\'444\'').should be_true
19
+ end
20
+ end
21
+ end
data/spec/spec.opts CHANGED
@@ -1 +1,3 @@
1
1
  --color
2
+ --format
3
+ specdoc
data/spec/spec_helper.rb CHANGED
@@ -20,7 +20,7 @@ end
20
20
 
21
21
  def map_query_string_to_file(query_string, file_name)
22
22
  api = query_string.include?('destination') ? 'directions' : 'geocode'
23
- map_url_to_file "http://maps.google.com/maps/api/#{api}/json?sensor=false&language=pt-BR&#{query_string}", file_name
23
+ map_url_to_file "http://maps.google.com/maps/api/#{api}/json?sensor=false&units=metric&#{query_string}", file_name
24
24
  end
25
25
 
26
26
  def map_url_to_file(url, file_name)
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gonow
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-09 00:00:00 -03:00
17
+ date: 2010-07-13 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -71,14 +71,17 @@ files:
71
71
  - .gitignore
72
72
  - README.markdown
73
73
  - Rakefile
74
+ - go_maps.gemspec
74
75
  - lib/go_maps.rb
75
76
  - lib/go_maps/address.rb
76
77
  - lib/go_maps/address_not_found_exception.rb
78
+ - lib/go_maps/direction.rb
77
79
  - spec/data/address_error
78
80
  - spec/data/address_success
79
81
  - spec/data/distance_error
80
82
  - spec/data/distance_success_10.8
81
83
  - spec/go_maps/address_spec.rb
84
+ - spec/go_maps/direction_spec.rb
82
85
  - spec/spec.opts
83
86
  - spec/spec_helper.rb
84
87
  has_rdoc: true
@@ -113,4 +116,5 @@ specification_version: 3
113
116
  summary: Ruby API to geographic operations
114
117
  test_files:
115
118
  - spec/go_maps/address_spec.rb
119
+ - spec/go_maps/direction_spec.rb
116
120
  - spec/spec_helper.rb