Conversation
HotelWhat We're Looking For
|
| def list_rooms | ||
| room_list = @rooms.map do |num| | ||
| "Room ##{num}" | ||
| end |
There was a problem hiding this comment.
When we said "access the list of all of the rooms in the hotel", we meant being able to call a method and get back an array of whatever your program uses to represent rooms. The attr_accessor :rooms above accomplishes this, and this method is not needed.
| def reservations_by_date(date) | ||
| reservations_by_date = reservations.select do |booking| | ||
| booking.in_date_range?(date) | ||
| end |
There was a problem hiding this comment.
Good use of the select enumerable to keep this code clean.
| def available_rooms_list(start_date, end_date) | ||
| until invalid_dates?(start_date, end_date) | ||
| rooms_occupied = occupied_rooms_list(start_date, end_date) | ||
| avail_rooms_array = @rooms - rooms_occupied |
There was a problem hiding this comment.
until is used to make a loop, but the body of this loop only runs once. You might want unless here instead.
There was a problem hiding this comment.
I love the problem solving approach here - you've done a good job of taking a big difficult problem (figure out which rooms are free) and turning it into two smaller problems (figure out which rooms are occupied, then take the inverse of that list).
|
|
||
| def total_cost | ||
| return ROOM_COST * total_nights | ||
| end |
There was a problem hiding this comment.
I like the decision to make this a method rather than storing the cost as an instance variable. That way if the number of nights or the cost per night were to change (say in a future version of the program), the total cost will automatically be correct.
| expect(hotel_system.occupied_rooms_list(Date.today + 1, Date.today + 7)).must_equal both_rooms | ||
| expect(hotel_system.occupied_rooms_list(Date.today + 2, Date.today + 3)).must_equal second_room | ||
| expect(hotel_system.occupied_rooms_list(Date.today - 3, Date.today + 1)).must_equal first_room | ||
| expect(hotel_system.occupied_rooms_list(Date.today + 2, Date.today + 7)).must_equal second_room |
There was a problem hiding this comment.
It might be wise to break each of these out as a separate test. That way if one fails, you know exactly what went wrong and have a nice human-readable name for it.
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions