forked from AdaGold/oo-ride-share
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Water - Mackenzie and Jessica #7
Open
jwinchan
wants to merge
37
commits into
Ada-C14:master
Choose a base branch
from
jwinchan: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
37 commits
Select commit
Hold shift + click to select a range
8ee9d3c
created 2 tests for time data in trips and read end and start times a…
jwinchan 765b606
added duration method
mvlofthus 96e8621
added duration test, returns accurate number of seconds
mvlofthus b775a93
created net_expenditure method
jwinchan 705b354
created 3 tests for net_expenditure
jwinchan 41abf54
added method total_time_spent and dry-ed up net_expenditures
mvlofthus 23add51
added core tests for total_time_spent, must return float and returns …
mvlofthus c36a5f9
added returns 0 for nil trips to total_time_spent
mvlofthus 503f1ab
created Driver class and set up initialization
jwinchan aa1ceab
released driver tests
jwinchan 97eb9bb
uncommented driver test helper
jwinchan 3a54a0e
update fro_csv, update status.to_sym
mvlofthus 1352de6
add driver_id, driver attributes
mvlofthus cd1ec45
added driver load all
mvlofthus 7abe50a
correct errors by including driver_id
mvlofthus 84fd603
correct errors by including driver_id
mvlofthus f8a7999
correct errors by including driver_id
mvlofthus 8d4de99
created add_trip method
jwinchan 3c4dd8e
updated connect to include driver parameter
jwinchan ba3864f
created find_driver method and updated connect_trips to include driver
jwinchan bb9ad35
unskipped driver test
jwinchan 3b692ed
added method average_rating and passed tests
mvlofthus 882cb1f
created total_revenue method
jwinchan 7348d66
updated to ternary operator
jwinchan 515cf10
updated inspect to include driver
jwinchan 2f05c14
created 2 tests for total_revenue method
jwinchan 42fde6c
created make_unavailable method
jwinchan 0d66bc8
modified initial values to nil, modified exception validations to acc…
jwinchan f861266
created request_trip method and two helper methods
jwinchan ab1c91f
created test to see if we can return Trip for request_trip
jwinchan 6e18cc6
added raise argument errror for no available drivers
mvlofthus 185527b
added tests for updating driver and passenger trip lists, selected dr…
mvlofthus 81e6934
refactored average_rating and total_revenue to account for trips in p…
jwinchan 1dff25b
refactored net_expenditures and total_time_spent to account for trips…
jwinchan c7a88bc
refactored duration method to account for end_time == nil
jwinchan a7dffc0
created test to account for trips in progress
jwinchan 7050dae
created tests to account for trips in progress
jwinchan 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 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,68 @@ | ||
require 'csv' | ||
require 'time' | ||
|
||
require_relative 'csv_record' | ||
|
||
module RideShare | ||
class Driver < CsvRecord | ||
attr_reader :id, :name, :vin, :status, :trips | ||
|
||
def initialize(id:, name:, vin:, status: :AVAILABLE, trips: []) | ||
raise ArgumentError.new("Invalid VIN length") unless vin.length == 17 | ||
raise ArgumentError.new("Invalid status") unless [:AVAILABLE, :UNAVAILABLE].include?(status.to_sym) | ||
|
||
super(id) | ||
|
||
@name = name | ||
@vin = vin | ||
@status = status.to_sym | ||
@trips = trips | ||
end | ||
|
||
def add_trip(trip) | ||
@trips << trip | ||
end | ||
|
||
def average_rating | ||
all_ratings = @trips.map { |trip| trip.rating } | ||
|
||
if all_ratings.length == 0 | ||
return 0 | ||
else | ||
average = all_ratings.compact.sum.to_f / all_ratings.compact.length | ||
return average | ||
end | ||
|
||
end | ||
|
||
def total_revenue | ||
all_cost = @trips.map do |trip| | ||
case trip.cost | ||
when nil | ||
nil | ||
when (0...1.65) | ||
0 | ||
else | ||
(trip.cost - 1.65) * 0.8 | ||
end | ||
end | ||
|
||
return all_cost.compact.sum | ||
end | ||
|
||
def make_unavailable | ||
@status = :UNAVAILABLE | ||
end | ||
|
||
private | ||
|
||
def self.from_csv(record) | ||
return new( | ||
id: record[:id], | ||
name: record[:name], | ||
vin: record[:vin], | ||
status: record[:status] | ||
) | ||
end | ||
end | ||
end |
This file contains 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 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 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 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.
CsvRecord
already includescsv
so including it here is not necessary. :)