This program consumes a .txt file of driver and trip data and returns a driving history report based on driver sorted by most to least total miles driven. Drivers with no valid trips will not be included in the generated report.
You can view the full problem statement here.
To use the generator, run the following command from the root-driving-report-generator directory in your terminal:
cat root_input.txt | ruby ./app/reports.rb
To run the tests, run the following commands from the root-driving-report-generator/test directory in your terminal:
ruby drivers_test.rb
ruby trips_test.rb
-
I took an object-oriented approach as this problem easily lends itself to this paradigm. I could instantly recognize the "nouns" and "verbs" in this problem. The nouns(classes) are reports, drivers, and trips. Each of these has its own set of actions (methods) that it needs to perform in order to generate the report.
-
The code is written as though the data has already been scrubbed. Typically I would write logic to ensure the data is standardized and corresponding tests, however the code sample instructions made it pretty clear that I should not give much attention to edge cases.
-
Used attr_reader instead of attr_accessor as an low-effort way to keep object permissions tight. This makes for cleaner, more maintainable code and reinforces the object-oriented modeling.
-
I chose to parse the
start_timeandend_timevalues inline so as to leave the data as true as possible. (Never know what the future holds!) -
I rounded the
total_distanceon output instead of on calculation soaverage_speedcould be calculated using the more accurate float value. -
I considered using a testing framework like RSpec but decided against it as the code reviewer may not have it installed and I always appreciate not having to do any yak shaving when reviewing code samples. I also considered building this out as a Rails app but thought that was a bit heavy for the ask. Would've been fun though! :)
- Add some logic for standardizing the data (just in case!)
- Add some helpful error-handling.
- Write more robust tests.
- Improve latency.
- I'd like to make sure the
tripsattribute in theDriverclass is storing a reference to thetripsinstances rather than the actual data. If it's not, I'd design a leaner approach.