roadtrip 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gitignore +4 -0
  2. data/Rakefile +13 -21
  3. data/VERSION +1 -0
  4. data/features/create_trip.feature +10 -0
  5. data/features/step_definitions/roadtrip_steps.rb +11 -0
  6. data/lib/roadtrip.rb +21 -32
  7. data/pkg/roadtrip-0.0.1.gem +0 -0
  8. data/pkg/roadtrip-0.0.1.tgz +0 -0
  9. data/pkg/roadtrip-0.0.1/History.txt +4 -0
  10. data/pkg/roadtrip-0.0.1/Manifest.txt +13 -0
  11. data/pkg/roadtrip-0.0.1/PostInstall.txt +3 -0
  12. data/pkg/roadtrip-0.0.1/README.rdoc +72 -0
  13. data/pkg/roadtrip-0.0.1/Rakefile +18 -0
  14. data/pkg/roadtrip-0.0.1/lib/roadtrip.rb +70 -0
  15. data/pkg/roadtrip-0.0.1/script/console +10 -0
  16. data/pkg/roadtrip-0.0.1/script/destroy +14 -0
  17. data/pkg/roadtrip-0.0.1/script/generate +14 -0
  18. data/pkg/roadtrip-0.0.1/spec/roadtrip_spec.rb +11 -0
  19. data/pkg/roadtrip-0.0.1/spec/spec.opts +1 -0
  20. data/pkg/roadtrip-0.0.1/spec/spec_helper.rb +10 -0
  21. data/pkg/roadtrip-0.0.1/tasks/rspec.rake +21 -0
  22. data/pkg/roadtrip-0.0.2.gem +0 -0
  23. data/pkg/roadtrip-0.0.2.tgz +0 -0
  24. data/pkg/roadtrip-0.0.2/History.txt +4 -0
  25. data/pkg/roadtrip-0.0.2/Manifest.txt +13 -0
  26. data/pkg/roadtrip-0.0.2/PostInstall.txt +3 -0
  27. data/pkg/roadtrip-0.0.2/README.rdoc +72 -0
  28. data/pkg/roadtrip-0.0.2/Rakefile +18 -0
  29. data/pkg/roadtrip-0.0.2/lib/roadtrip.rb +70 -0
  30. data/pkg/roadtrip-0.0.2/script/console +10 -0
  31. data/pkg/roadtrip-0.0.2/script/destroy +14 -0
  32. data/pkg/roadtrip-0.0.2/script/generate +14 -0
  33. data/pkg/roadtrip-0.0.2/spec/roadtrip_spec.rb +11 -0
  34. data/pkg/roadtrip-0.0.2/spec/spec.opts +1 -0
  35. data/pkg/roadtrip-0.0.2/spec/spec_helper.rb +10 -0
  36. data/pkg/roadtrip-0.0.2/tasks/rspec.rake +21 -0
  37. data/pkg/roadtrip-0.0.3.gem +0 -0
  38. data/pkg/roadtrip-0.0.3.tgz +0 -0
  39. data/pkg/roadtrip-0.0.3/History.txt +4 -0
  40. data/pkg/roadtrip-0.0.3/Manifest.txt +13 -0
  41. data/pkg/roadtrip-0.0.3/PostInstall.txt +3 -0
  42. data/pkg/roadtrip-0.0.3/README.rdoc +72 -0
  43. data/pkg/roadtrip-0.0.3/Rakefile +18 -0
  44. data/pkg/roadtrip-0.0.3/lib/roadtrip.rb +70 -0
  45. data/pkg/roadtrip-0.0.3/script/console +10 -0
  46. data/pkg/roadtrip-0.0.3/script/destroy +14 -0
  47. data/pkg/roadtrip-0.0.3/script/generate +14 -0
  48. data/pkg/roadtrip-0.0.3/spec/roadtrip_spec.rb +11 -0
  49. data/pkg/roadtrip-0.0.3/spec/spec.opts +1 -0
  50. data/pkg/roadtrip-0.0.3/spec/spec_helper.rb +10 -0
  51. data/pkg/roadtrip-0.0.3/tasks/rspec.rake +21 -0
  52. data/pkg/roadtrip-0.1.0.gem +0 -0
  53. data/roadtrip.gemspec +105 -0
  54. data/spec/roadtrip_spec.rb +9 -1
  55. metadata +67 -68
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ coverage/*
3
+ coverage.data
4
+ autotest_images
data/Rakefile CHANGED
@@ -1,26 +1,18 @@
1
1
  require 'rubygems'
2
- gem 'hoe', '>= 2.1.0'
3
- require 'hoe'
4
2
  require 'fileutils'
5
3
  require './lib/roadtrip'
6
4
 
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
-
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gemspec|
8
+ gemspec.name = "roadtrip"
9
+ gemspec.summary = "Use Google Maps to find the cost, duration and distance for road trips"
10
+ gemspec.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."
11
+ gemspec.email = "kentonnewby@gmail.com"
12
+ gemspec.homepage = "http://github.com/kenton/roadtrip"
13
+ gemspec.authors = ["Kenton Newby"]
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: gem install jeweler"
19
18
  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/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,10 @@
1
+ Feature: create trip
2
+ As a road tripper
3
+ I want to create a new trip
4
+ So that I can find out how much it will cost to get there
5
+
6
+ Scenario: create trip
7
+ Given I haven't created a trip yet
8
+ When I create a new trip
9
+ Then I should see "..."
10
+ And I should see "..."
@@ -0,0 +1,11 @@
1
+ Given /^I haven't created a trip yet$/ do
2
+
3
+ end
4
+
5
+ When /^I create a new trip$/ do
6
+ pending # express the regexp above with the code you wish you had
7
+ end
8
+
9
+ Then /^I should see "([^\"]*)"$/ do |arg1|
10
+ pending # express the regexp above with the code you wish you had
11
+ end
@@ -7,10 +7,10 @@ require 'pp'
7
7
  require 'ap'
8
8
 
9
9
  module Roadtrip
10
- VERSION = '0.0.3'
11
-
12
- dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
10
+ VERSION = '0.0.4'
11
+ MILES_PER_METER = 0.000621371192
13
12
 
13
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
14
14
 
15
15
  class Trip
16
16
  include HTTParty
@@ -24,41 +24,30 @@ module Roadtrip
24
24
  @cost_per_gallon = cost_per_gallon
25
25
  @mpg = mpg
26
26
  end
27
-
27
+
28
+ def trip
29
+ 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
+ end
36
+
28
37
  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
38
  trip["routes"][0]["legs"][0]["distance"]["text"]
37
39
  end
38
-
40
+
39
41
  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
42
  trip["routes"][0]["legs"][0]["duration"]["text"]
48
43
  end
49
-
44
+
45
+ def distance_in_miles
46
+ MILES_PER_METER * trip["routes"][0]["legs"][0]["distance"]["value"]
47
+ end
48
+
50
49
  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
50
+ distance_in_miles * self.cost_per_gallon / mpg
62
51
  end
63
52
 
64
53
  def round_trip_cost
@@ -67,4 +56,4 @@ module Roadtrip
67
56
 
68
57
  end
69
58
 
70
- end
59
+ end
Binary file
Binary file
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2010-06-20
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -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
@@ -0,0 +1,3 @@
1
+ For more information on roadtrip, see http://github.com/kenton/roadtrip
2
+
3
+
@@ -0,0 +1,72 @@
1
+ = roadtrip
2
+
3
+ * http://github.com/kenton/roadtrip
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
+ == EXAMPLE USE:
10
+ Assume a user is traveling from ZIP code 30032 to ZIP code 90210, that gas costs $2.75 per gallon and that the car being driven has a fuel economy of 30mpg. The following would be used to create an instance of a Roadtrip::Trip, labeled "t" in this case:
11
+
12
+ t = Roadtrip::Trip.new(30032, 90210, 2.75, 30)
13
+
14
+ So in general, the user supplies the following parameters:
15
+
16
+ * Starting Location
17
+ * Destination
18
+ * Cost Per Gallon - the cost for a gallon of gas, on average
19
+ * Miles Per Gallon - the MPG for your vehicle
20
+
21
+ == FEATURES:
22
+
23
+ Each "RoadTrip::Trip" object has the following methods available:
24
+
25
+ t.distance
26
+ t.duration
27
+ t.cost
28
+ t.round_trip_cost
29
+
30
+ == TESTS:
31
+ This is a brand new gem (and my first), so I'm still working through adding Cucumber/RSpec tests. For now, this was just a proof of concept so I knew how to create/deploy a gem. I plan on going back and continuing development of this gem using BDD/TDD. More to follow...
32
+
33
+ == REQUIREMENTS:
34
+ This gem has the following dependencies:
35
+
36
+ * rubygems (of course)
37
+ * httparty (http://github.com/jnunemaker/httparty)
38
+
39
+ == INSTALL:
40
+
41
+ (sudo) gem install roadtrip
42
+
43
+ Then in your ruby code, add:
44
+ require 'rubygems'
45
+ require 'roadtrip'
46
+
47
+ Note: This gem is hosted at http://www.rubygems.org. Be sure you have rubygems.org (or gemcutter.org) listed as a gem source on your system...or see the documentation on their site for how to add this as a source.
48
+
49
+ == LICENSE:
50
+
51
+ (The MIT License)
52
+
53
+ Copyright (c) 2010 Kenton Newby
54
+
55
+ Permission is hereby granted, free of charge, to any person obtaining
56
+ a copy of this software and associated documentation files (the
57
+ 'Software'), to deal in the Software without restriction, including
58
+ without limitation the rights to use, copy, modify, merge, publish,
59
+ distribute, sublicense, and/or sell copies of the Software, and to
60
+ permit persons to whom the Software is furnished to do so, subject to
61
+ the following conditions:
62
+
63
+ The above copyright notice and this permission notice shall be
64
+ included in all copies or substantial portions of the Software.
65
+
66
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
67
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
68
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
69
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
70
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
71
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
72
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'fileutils'
3
+ require './lib/roadtrip'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gemspec|
8
+ gemspec.name = "roadtrip"
9
+ gemspec.summary = "Use Google Maps to find the cost, duration and distance for road trips"
10
+ gemspec.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."
11
+ gemspec.email = "kentonnewby@gmail.com"
12
+ gemspec.homepage = "http://github.com/kenton/roadtrip"
13
+ gemspec.authors = ["Kenton Newby"]
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: gem install jeweler"
18
+ end
@@ -0,0 +1,70 @@
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.3'
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
@@ -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"
@@ -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)
@@ -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 "should find the distance between the starting point and the end point" do
8
+ # violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
@@ -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'
@@ -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
Binary file
Binary file
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2010-06-20
2
+
3
+ * 1 major enhancement:
4
+ * Initial release