Conversation
…ull up list of rooms
…esk has access to everything
…gument error if room is not available
…and reformatting line lengths
…g tests, refactor and clean, simplify arguments for blocks
HotelWhat We're Looking For
|
| @@ -0,0 +1,2 @@ | |||
| class AvailabilityError < StandardError | |||
| raise ArgumentError, "Block doesn't exist" unless block | ||
| end | ||
|
|
||
| def validate_size(number_of_rooms:) |
There was a problem hiding this comment.
I would consider moving this code into Block since the FrontDesk doesn't really need to know about the maximum number of rooms a block can have.
| end | ||
|
|
||
| def validate_size(number_of_rooms:) | ||
| max_rooms_for_block = 5 |
There was a problem hiding this comment.
This should be a constant, probably also in Block. The reason a constant would be useful here is if we change the rules about how many rooms can be used in a block there's a clear single place to change it.
| raise ArgumentError, "Reservation must be at least one day long" if check_in >= check_out | ||
| end | ||
|
|
||
| def validate_date_arguments(check_in: nil, check_out: nil, nights: nil) |
There was a problem hiding this comment.
The date validation also probably doesn't want to live in FrontDesk since that's unrelated to its job of managing the high level state of the hotel. (There are other methods that might want to be moved out as well but which ones would depend on your specific solution.)
There are two main ways to avoid repeating this in Reservation and Block:
- Make an
IntervalorDateRangeclass that's responsible for validation/comparison of dates. - Make a parent class for both
BlockandReservationthat handles the above functionality.
| rooms.select { |room| room.available?(nights: nights) } | ||
| end | ||
|
|
||
| def create_block(check_in:, check_out:, room_collection: nil, number_of_rooms: nil, room_rate:) |
There was a problem hiding this comment.
Most of this logic probably wants to live in Block. This method is rather coupled to the state of FrontDesk though so the challenging part would be figuring out how little you could get away with passing into the Block class.
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions