roadtrip 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2010-06-20
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,13 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/roadtrip.rb
7
+ script/console
8
+ script/destroy
9
+ script/generate
10
+ spec/roadtrip_spec.rb
11
+ spec/spec.opts
12
+ spec/spec_helper.rb
13
+ tasks/rspec.rake
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on roadtrip, see http://roadtrip.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,63 @@
1
+ = roadtrip
2
+
3
+ * http://github.com/#{github_username}/#{project_name}
4
+
5
+ == DESCRIPTION:
6
+
7
+ This is a quick little gem that uses Google Maps to determine the distance, duration and fuel costs for driving between two user defined points. Just like Google Maps, the starting and destination points can be full addresses, city/state combinations, or just ZIP codes.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Pending
12
+
13
+ == SYNOPSIS:
14
+
15
+ t = Trip.new(30032, 90210, 2.75, 30)
16
+
17
+ The user supplies the following parameters:
18
+
19
+ Starting Location
20
+ Destination
21
+ Cost Per Gallon - the cost for a gallon of gas, on average
22
+ Miles Per Gallon - the MPG for your vehicle
23
+
24
+ Each object has the following methods available:
25
+
26
+ t.distance
27
+ t.duration
28
+ t.cost
29
+ t.round_trip_cost
30
+
31
+
32
+ == REQUIREMENTS:
33
+
34
+ * FIX (list of requirements)
35
+
36
+ == INSTALL:
37
+
38
+ sudo gem install roadtrip
39
+
40
+ == LICENSE:
41
+
42
+ (The MIT License)
43
+
44
+ Copyright (c) 2010 Kenton Newby
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining
47
+ a copy of this software and associated documentation files (the
48
+ 'Software'), to deal in the Software without restriction, including
49
+ without limitation the rights to use, copy, modify, merge, publish,
50
+ distribute, sublicense, and/or sell copies of the Software, and to
51
+ permit persons to whom the Software is furnished to do so, subject to
52
+ the following conditions:
53
+
54
+ The above copyright notice and this permission notice shall be
55
+ included in all copies or substantial portions of the Software.
56
+
57
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
58
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
59
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
60
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
61
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
62
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
63
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/roadtrip'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'roadtrip' do
14
+ self.developer 'Kenton Newby', 'kentonnewby@gmail.com'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
data/lib/roadtrip.rb ADDED
@@ -0,0 +1,123 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'rubygems'
5
+ require 'httparty'
6
+ require 'pp'
7
+ require 'ap'
8
+
9
+ module Roadtrip
10
+ VERSION = '0.0.1'
11
+
12
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+
14
+
15
+ class Trip
16
+ include HTTParty
17
+ format :json
18
+
19
+ attr_accessor :start, :destination, :cost_per_gallon, :mpg
20
+
21
+ def initialize(start, destination, cost_per_gallon, mpg)
22
+ @start = start
23
+ @destination = destination
24
+ @cost_per_gallon = cost_per_gallon
25
+ @mpg = mpg
26
+ end
27
+
28
+ def distance
29
+ trip = Trip.get('http://maps.google.com/maps/api/directions/json?',
30
+ :query => {
31
+ :origin => self.start,
32
+ :destination => self.destination,
33
+ :sensor => "false"
34
+ })
35
+
36
+ trip["routes"][0]["legs"][0]["distance"]["text"]
37
+ end
38
+
39
+ def duration
40
+ trip = Trip.get('http://maps.google.com/maps/api/directions/json?',
41
+ :query => {
42
+ :origin => self.start,
43
+ :destination => self.destination,
44
+ :sensor => "false"
45
+ })
46
+
47
+ trip["routes"][0]["legs"][0]["duration"]["text"]
48
+ end
49
+
50
+ def cost
51
+ trip = Trip.get('http://maps.google.com/maps/api/directions/json?',
52
+ :query => {
53
+ :origin => self.start,
54
+ :destination => self.destination,
55
+ :sensor => "false"
56
+ })
57
+
58
+ distance = trip["routes"][0]["legs"][0]["distance"]["value"]
59
+ miles = distance * 0.000621371192
60
+ cost = (self.cost_per_gallon / mpg) * miles
61
+ return cost
62
+ end
63
+
64
+ def round_trip_cost
65
+ self.cost * 2
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+
72
+
73
+ # puts "Enter Starting Address or Location"
74
+ # start_location = gets
75
+ # puts "Enter Destination"
76
+ # end_location = gets
77
+ # puts "Enter MPG for your vehicle"
78
+ # mpg = gets.to_f
79
+ # puts "Enter gas cost per gallon"
80
+ # gas_price_per_gallon = gets.to_f
81
+
82
+ # trip = Trip.get('http://maps.google.com/maps/api/directions/json?',
83
+ # :query => {
84
+ # :origin => start_location,
85
+ # :destination => end_location,
86
+ # :sensor => "false"
87
+ # })
88
+
89
+ # ap trip["routes"][0]["legs"][0]
90
+
91
+ # distance = trip["routes"][0]["legs"][0]["distance"]["value"]
92
+ # miles = distance * 0.000621371192
93
+ # cost = (gas_price_per_gallon / mpg) * miles
94
+
95
+ # puts "\n"
96
+ # puts "----------------------------------------------------------------------"
97
+ # puts "Start Address: #{trip["routes"][0]["legs"][0]["start_address"]}"
98
+ # puts "End Address: #{trip["routes"][0]["legs"][0]["end_address"]}"
99
+ # puts "Distance: #{trip["routes"][0]["legs"][0]["distance"]["text"]}"
100
+ # puts "Duration: #{trip["routes"][0]["legs"][0]["duration"]["text"]}"
101
+ # puts "Cost (one-way): $#{cost.to_f.round}"
102
+ # puts "Cost (round trip): $#{cost.to_f.round * 2}"
103
+ # puts "----------------------------------------------------------------------"
104
+ # puts "\n"
105
+
106
+
107
+
108
+ # ap distance["routes"][0]["legs"][0]
109
+ # puts "#{distance["routes"][0]["legs"]["starting_address"]}"
110
+ # puts "#{distance["routes"][0]["start_address"]}"
111
+
112
+
113
+ # * origin (required) — The address or textual latitude/longitude value from which you wish to calculate directions. *
114
+ # * destination (required) — The address or textual latitude/longitude value from which you wish to calculate directions.*
115
+ # * mode (optional, defaults to driving) — specifies what mode of transport to use when calculating directions. Valid values are specified in Travel Modes.
116
+ # * waypoints (optional) specifies an array of waypoints. Waypoints alter a route by routing it through the specified location(s). A waypoint is specified as either a latitude/longitude coordinate or as an address which will be geocoded. (For more information on waypoints, see Using Waypoints in Routes below.)
117
+ # * alternatives (optional), if set to true, specifies that the Directions service may provide more than one route alternative in the response. Note that providing route alternatives may increase the response time from the server.
118
+ # * avoid (optional) indicates that the calculated route(s) should avoid the indicated features. Currently, this parameter supports the following two arguments:
119
+ # o tolls indicates that the calculated route should avoid toll roads/bridges.
120
+ # o highways indicates that the calculated route should avoid highways.
121
+ # (For more information see Route Restrictions below.)
122
+ # * language (optional) — The language in which to return results. See the supported list of domain languages. Note that we often update supported languages so this list may not be exhaustive. If language is not supplied, the Directions service will attempt to use the native language of the browser wherever possible. You may also explicitly bias the results by using localized domains of http://map.google.com. See Region Biasing for more information.
123
+ # * sensor (required) — Indicates whether or not the directions request comes from a device with a location sensor. This value must be either true or false.
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/roadtrip.rb'}"
9
+ puts "Loading roadtrip gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ # violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'roadtrip'
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roadtrip
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Kenton Newby
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-06 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rubyforge
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 4
34
+ version: 2.0.4
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: gemcutter
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 11
46
+ segments:
47
+ - 0
48
+ - 5
49
+ - 0
50
+ version: 0.5.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: hoe
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 27
62
+ segments:
63
+ - 2
64
+ - 5
65
+ - 0
66
+ version: 2.5.0
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: This is a quick little gem that uses Google Maps to determine the distance, duration and fuel costs for driving between two user defined points. Just like Google Maps, the starting and destination points can be full addresses, city/state combinations, or just ZIP codes.
70
+ email:
71
+ - kentonnewby@gmail.com
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ extra_rdoc_files:
77
+ - History.txt
78
+ - Manifest.txt
79
+ - PostInstall.txt
80
+ files:
81
+ - History.txt
82
+ - Manifest.txt
83
+ - PostInstall.txt
84
+ - README.rdoc
85
+ - Rakefile
86
+ - lib/roadtrip.rb
87
+ - script/console
88
+ - script/destroy
89
+ - script/generate
90
+ - spec/roadtrip_spec.rb
91
+ - spec/spec.opts
92
+ - spec/spec_helper.rb
93
+ - tasks/rspec.rake
94
+ has_rdoc: true
95
+ homepage: http://github.com/#{github_username}/#{project_name}
96
+ licenses: []
97
+
98
+ post_install_message: PostInstall.txt
99
+ rdoc_options:
100
+ - --main
101
+ - README.rdoc
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirements: []
123
+
124
+ rubyforge_project: roadtrip
125
+ rubygems_version: 1.3.7
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: This is a quick little gem that uses Google Maps to determine the distance, duration and fuel costs for driving between two user defined points
129
+ test_files: []
130
+