Conversation
OO Ride ShareMajor Learning Goals/Code Review
Testing Requirements
Overall Feedback
Code Style Bonus AwardsWas the code particularly impressive in code style for any of these reasons (or more...?)
|
kaidamasaki
left a comment
There was a problem hiding this comment.
Good job! Here are some tips for how you can clean up your code. 😄
| @status = status.to_sym | ||
| @trips = trips || [] | ||
|
|
||
| vin_pattern = /^[A-Z0-9]{17}$/i |
|
|
||
| vin_pattern = /^[A-Z0-9]{17}$/i | ||
| if (vin_pattern =~ @vin) == nil | ||
| raise ArgumentError, "Invalid VIN" |
There was a problem hiding this comment.
It's helpful to include the bad argument in the message for your ArgumentErrors:
| raise ArgumentError, "Invalid VIN" | |
| raise ArgumentError, "Invalid VIN: #{@vin}" |
| @trips << trip | ||
| end | ||
|
|
||
| def change_status |
There was a problem hiding this comment.
The name change_status is misleading since it just sets the status to :UNAVAILABLE.
| def change_status | |
| def make_unavailable |
| else | ||
| (trip.rating).to_f | ||
| end |
There was a problem hiding this comment.
Incorrect indentation:
| else | |
| (trip.rating).to_f | |
| end | |
| else | |
| (trip.rating).to_f | |
| end |
| cost = ((average_rating).inject(:+))/((average_rating.length) - nil_cases) | ||
| return cost |
There was a problem hiding this comment.
You have a lot of extra parenthesis and can directly return the result of this computation, also inject(:+) is the same as sum):
| cost = ((average_rating).inject(:+))/((average_rating.length) - nil_cases) | |
| return cost | |
| return average_rating.sum / (average_rating.length - nil_cases) |
Remember, . has higher precedence than arithmetic.
| @passenger = RideShare::Passenger.new( | ||
| id: 9, | ||
| name: "Merl Glover III", | ||
| phone_number: "1-602-620-2330 x3723", | ||
| trips: [] | ||
| ) |
There was a problem hiding this comment.
Incorrect indentation:
| @passenger = RideShare::Passenger.new( | |
| id: 9, | |
| name: "Merl Glover III", | |
| phone_number: "1-602-620-2330 x3723", | |
| trips: [] | |
| ) | |
| @passenger = RideShare::Passenger.new( | |
| id: 9, | |
| name: "Merl Glover III", | |
| phone_number: "1-602-620-2330 x3723", | |
| trips: [] | |
| ) |
|
|
||
| # 1.1 #4 instance method of duration of trip | ||
| def duration | ||
| return (Time.parse(@end_time) - Time.parse(@start_time)).to_i |
There was a problem hiding this comment.
You're already parsing the time in from_csv so this is redundant.
| start_time: "#{Time.now - 60 * 60}", | ||
| end_time: "#{Time.now + 60 * 60}", |
There was a problem hiding this comment.
You should just pass Time objects into the test.
| start_time: "#{Time.now - 60 * 60}", | |
| end_time: "#{Time.now + 60 * 60}", | |
| start_time: Time.now - 60 * 60, | |
| end_time: Time.now + 60 * 60, |
|
|
||
| # handles case when there are no available drivers | ||
| if @drivers.find {|driver| driver.status == :AVAILABLE}.nil? | ||
| raise ArgumentError.new("No available drivers.") |
There was a problem hiding this comment.
This isn't an issue with the arguments here. You should use a custom error class here.
For example at the top of the file you can define:
class NoDriverError < StandardError
endAnd then:
| raise ArgumentError.new("No available drivers.") | |
| raise NoDriverError.new("No available drivers.") |
| @driver.change_status | ||
|
|
||
| @trip_data = { | ||
| id: @trips.last.id + 1, |
There was a problem hiding this comment.
Nice use of last here to assign a unique id.
Assignment Submission: OO Ride Share
Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.
Reflection
nil?which didn't work at first. Then we realized we had use.empty?becausenil?refers nothing whereas @trips had an empty array which is not nil. This led us to realize.empty?was the best choice because it covered the case we were looking for.def self.from_csv(record).net_expendituresmethod, we wrote a nominal test forit "returns the correct total amount of money that a passenger has spent"average_ratingwe wrote an edge case test forit "returns zero if no driven trips" doandit "returns 0 if trip costs <= $1.65" do