-
Notifications
You must be signed in to change notification settings - Fork 28
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
Melissa_Pushpa_Edges_OO_RideShare #24
base: master
Are you sure you want to change the base?
Changes from all commits
bafad52
36cd4ef
fa81cd2
8e87c64
80691e2
e557f9e
17d2d57
e9ea4c8
73e59b3
26d0084
c462dc7
7786a7b
f6d990d
99d9fc9
b86a02e
4ee9bfc
504ba78
cd614e3
f47211e
55281ff
f3a0dc1
02bbe41
a1e6481
9ef0cb6
98806cb
6d6728e
9fbfce8
90216ff
5de24c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
require_relative 'trip' | ||
require 'pry' | ||
|
||
module RideShare | ||
|
||
class Driver < User | ||
|
||
attr_reader :vin, :status, :driven_trips | ||
|
||
def initialize(input) | ||
|
||
if input[:id].nil? || input[:id] <= 0 | ||
raise ArgumentError, 'ID cannot be blank or less than zero.' | ||
end | ||
|
||
if input[:vin] == nil || input[:vin].length != 17 || input[:vin] == " " | ||
# binding.pry | ||
raise ArgumentError, 'Vin inaccurate, must be 17 characters long.' | ||
end | ||
|
||
|
||
super(input) | ||
# @id = input[:id].to_i | ||
# @name = input[:name].to_s | ||
@vin = input[:vin].to_s | ||
@status = input[:status] | ||
@driven_trips = [] | ||
|
||
# status_array = [:AVAILABLE, :UNAVAILABLE ] | ||
|
||
|
||
|
||
|
||
# binding.pry | ||
# unless @status.include?(status_array) | ||
# raise ArgumentError. "Invalid status, you entered: #{status}" | ||
# end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this commented out? It does look like line 35 is backward (should be |
||
|
||
|
||
end | ||
|
||
def add_driven_trip(trip) | ||
unless trip.is_a? Trip | ||
raise ArgumentError, "Got a thing that wasn't a trip! (#{trip.class})" | ||
end | ||
@driven_trips << trip | ||
|
||
end | ||
|
||
|
||
|
||
|
||
def average_rating #sums rating from all drivers trips and returns the average | ||
trip_sum = 0.0 | ||
@driven_trips.each do |trip| | ||
trip_sum += trip.rating | ||
end | ||
if @driven_trips == [] | ||
return 0 | ||
else | ||
return trip_sum / @driven_trips.length | ||
end | ||
end | ||
|
||
|
||
def total_revenue #calculates the drivers total revenue across all of the trips | ||
sum = 0.0 | ||
sum_tax = 1.65 | ||
total_rev = 0 | ||
@driven_trips.each do |trip| | ||
sum = (trip.cost - sum_tax) * 0.8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code would be a little more readable if the two magic numbers ( |
||
total_rev += sum | ||
end | ||
return total_rev | ||
end | ||
|
||
def net_expenditures | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One possible implementation: def net_expenditures
return (super - total_revenue).round(2)
end The key here is taking advantage of code you've already written, both from the parent class using |
||
|
||
|
||
end | ||
|
||
|
||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require 'pry' | ||
|
||
module RideShare | ||
class User | ||
attr_reader :id, :name, :phone_number, :trips | ||
|
@@ -7,7 +9,7 @@ def initialize(input) | |
raise ArgumentError, 'ID cannot be blank or less than zero.' | ||
end | ||
|
||
@id = input[:id] | ||
@id = input[:id] #user_ID/PassengerID | ||
@name = input[:name] | ||
@phone_number = input[:phone] | ||
@trips = input[:trips].nil? ? [] : input[:trips] | ||
|
@@ -16,5 +18,27 @@ def initialize(input) | |
def add_trip(trip) | ||
@trips << trip | ||
end | ||
|
||
|
||
# return total amount of money user spent on trips | ||
def net_expenditures | ||
ride_total = 0 | ||
@trips.each do |trip| | ||
ride_total += trip[:cost] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both these methods will hit an error if you try to run them on a user with an incomplete trip. There are a couple of workarounds for this. You could explicitly ignore trips with a trips.each do |trip|
if trip.cost.nil?
next
end
# ... add to the total ...
end Or even better, you could write a helper method that returns a list of complete trips: def completed_trips
return @trips.reject { |t| t.end_time.nil? }
end
def net_expenditures
completed_trips.each do |trip|
# ... same logic as before ...
end
end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the above is true, it is less relevant given that you didn't complete wave 3. |
||
end | ||
return ride_total | ||
end | ||
|
||
# RideShare::Trip.duration - don't need RideShare? NO, same module | ||
|
||
# return total amout of time user has spent on the trips | ||
def total_time_spent | ||
total_time = 0 | ||
@trips.each do |trip| | ||
trip_in_seconds = trip[:end_time] - trip[:start_time] | ||
total_time += trip_in_seconds | ||
end | ||
return total_time | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
id,driver_id,passenger_id,start_time,end_time,cost,rating | ||
1,2,1,2018-05-25 11:52:40 -0700,2018-05-25 12:25:00 -0700,10,5 | ||
2,2,3,2018-07-23 04:39:00 -0700,2018-07-25 04:55:00 -0700,7,3 | ||
2,2,3,2018-07-23 04:39:00 -0700,2018-07-23 04:55:00 -0700,7,3 | ||
3,5,4,2018-06-11 22:22:00 -0700,2018-06-11 22:57:00 -0700,15,4 | ||
4,5,7,2018-08-12 15:04:00 -0700,2018-08-12 15:14:00 -0700,8,1 | ||
5,5,6,2018-08-05 08:58:00 -0700,2018-08-05 09:30:00 -0700,32,1 | ||
5,5,6,2018-08-05 08:58:00 -0700,2018-08-05 09:30:00 -0700,32,1 |
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.
Doesn't
User
already check this? If not it probably should.