As we want to provide a better experience for our users, we aim to represent their itinerary in the most comprehensive way possible.
We receive the reservations of our user, who we know is based in SVQ, as:
# input.txt
RESERVATION
SEGMENT: Flight SVQ 2023-03-02 06:40 -> BCN 09:10
RESERVATION
SEGMENT: Hotel BCN 2023-01-05 -> 2023-01-10
RESERVATION
SEGMENT: Flight SVQ 2023-01-05 20:40 -> BCN 22:10
SEGMENT: Flight BCN 2023-01-10 10:30 -> SVQ 11:50
RESERVATION
SEGMENT: Train SVQ 2023-02-15 09:30 -> MAD 11:00
SEGMENT: Train MAD 2023-02-17 17:00 -> SVQ 19:30
RESERVATION
SEGMENT: Hotel MAD 2023-02-15 -> 2023-02-17
RESERVATION
SEGMENT: Flight BCN 2023-03-02 15:00 -> NYC 22:45
When running a command like BASED=SVQ bundle exec ruby main.rb input.txt, we want to display a UI like this:
TRIP to BCN
Flight from SVQ to BCN at 2023-01-05 20:40 to 22:10
Hotel at BCN on 2023-01-05 to 2023-01-10
Flight from BCN to SVQ at 2023-01-10 10:30 to 11:50
TRIP to MAD
Train from SVQ to MAD at 2023-02-15 09:30 to 11:00
Hotel at MAD on 2023-02-15 to 2023-02-17
Train from MAD to SVQ at 2023-02-17 17:00 to 19:30
TRIP to NYC
Flight from SVQ to BCN at 2023-03-02 06:40 to 09:10
Flight from BCN to NYC at 2023-03-02 15:00 to 22:45
You have to write Ruby code that reads the input from the file input.txt and prints the expected output.
Take into account the following aspects:
- You should implement the sorting and grouping logic for the segments.
- You can assume that segments won’t overlap.
- IATA codes are always three-letter uppercase strings: SVQ, MAD, BCN, NYC
- You can use external frameworks or libraries if you want.
- You can attach notes explaining the solution and why certain things are included and others are left out.
- You may consider two flights to be a connection if there is less than 24 hours difference.
- The solution should be production-ready.
- You should provide a solution that is easy to extend.
You can reply to the email you received if you have any doubts.
In order to submit your solution, create your own GitHub repository and send it to us by email once it is ready.
Thank you very much for your time and good luck!