forked from AdaGold/oo-ride-share
-
Notifications
You must be signed in to change notification settings - Fork 29
Time - Lola - Yoyo #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ydunbar
wants to merge
21
commits into
Ada-C13:master
Choose a base branch
from
ydunbar:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
64d1b3d
Attempted Wave 1.1: Upgrading Times
ydunbar e67c4cb
Corrected error in trip.rb's ArgumentError for when end_time is not l…
ydunbar 18f6015
Added and passed test for raising ArgumentError when trip end time is…
ydunbar 373936e
Added method to calculate tripduration in seconds, and wrote and pass…
ydunbar d25b549
Added methods to passenger to find net expenditures and total time spent
ydunbar 9cb6a2f
Added test for Passenger net_expenditures method
ydunbar 2533a5e
Added test for Passenger total_time_spent method
ydunbar 0d7fab1
Created driver.rb file and began creating the Driver class
ydunbar cff5926
Added methods for Driver class and attempted to pass tests
ydunbar 95df3cf
Worked on passing tests for Wave 1 with Driver class added
ydunbar 6f9f63f
Re-ordered code in Driver's initialize method to be in more logical a…
ydunbar 3e77aa1
Started re-factoring Wave 1 tests
ydunbar 0c497da
added tests to passenger_test.rb
ydunbar 4824c6b
Got Wave 2 tests passing
ydunbar 21221c4
Added request_trip method for Wave 3
ydunbar 00bbef0
fixed indentation and syntax in TripDispatcher
ydunbar ffdc291
Refactored request_trip method
ydunbar 0846868
added a test for request_trip
ydunbar c5109dc
Refactored request_trip method
ydunbar c9068b4
Passed tests for Wave 3
ydunbar 0184427
cleaned up extra spaces and comments
ydunbar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| source 'http://rubygems.org' | ||
|
|
||
| ruby '2.5.5' | ||
| ruby '2.6.3' | ||
|
|
||
| gem 'rake' | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| GEM | ||
| remote: http://rubygems.org/ | ||
| specs: | ||
| ansi (1.5.0) | ||
| awesome_print (1.8.0) | ||
| builder (3.2.4) | ||
| csv (3.1.2) | ||
| minitest (5.14.0) | ||
| minitest-reporters (1.4.2) | ||
| ansi | ||
| builder | ||
| minitest (>= 5.0) | ||
| ruby-progressbar | ||
| minitest-skip (0.0.1) | ||
| minitest (~> 5.0) | ||
| rake (13.0.1) | ||
| ruby-progressbar (1.10.1) | ||
|
|
||
| PLATFORMS | ||
| ruby | ||
|
|
||
| DEPENDENCIES | ||
| awesome_print | ||
| csv | ||
| minitest | ||
| minitest-reporters | ||
| minitest-skip | ||
| rake | ||
|
|
||
| RUBY VERSION | ||
| ruby 2.6.3p62 | ||
|
|
||
| BUNDLED WITH | ||
| 2.1.4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| require_relative "csv_record" | ||
|
|
||
| module RideShare | ||
| class Driver < CsvRecord | ||
| attr_reader :name, :vin, :trips | ||
| attr_accessor :status | ||
|
|
||
| def initialize(id:, name:, vin: nil, status: :AVAILABLE, trips: nil) | ||
| super(id) | ||
| @name = name | ||
| if vin.length != 17 | ||
| raise ArgumentError, "vin must be 17 characters long" | ||
| end | ||
| @vin = vin | ||
| @status = status | ||
| @trips = trips || [] | ||
| end | ||
|
|
||
| def add_trip(trip) | ||
| @trips << trip | ||
| end | ||
|
|
||
| def average_rating | ||
| rating_total = 0 | ||
| if @trips.empty? | ||
| return 0 | ||
| else | ||
| @trips.each do |trip| | ||
| rating_total += trip.rating | ||
| end | ||
| return rating_total / @trips.length.to_f.round(2) | ||
| end | ||
| end | ||
|
|
||
| def total_revenue | ||
| total_revenue = 0 | ||
| if @trips.empty? | ||
| return 0 | ||
| else | ||
| @trips.each do |trip| | ||
| if trip.cost >= 1.65 | ||
| total_revenue += trip.cost * 0.8 - 1.65 | ||
| else | ||
| total_revenue | ||
| end | ||
| end | ||
| end | ||
| return total_revenue | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def self.from_csv(record) | ||
| return self.new( | ||
| id: record[:id], | ||
| name: record[:name], | ||
| vin: record[:vin], | ||
| status: record[:status].to_sym, | ||
| ) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really good opportunity for refactoring to use an Enumerable method, like
sum, instead of needing to incrementrating_totalin aneachloop