-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Katricia - Edges - Hotel #35
base: master
Are you sure you want to change the base?
Conversation
… list, list rooms, list reservations, get cost
…manager already requires room
…or Populate Room List method
…qual to constructor parameter passed in
…kingManager#populate_room_list
…n_date pseudocode
…reflect date format Month dd, yyyy
…stances to hotel.rooms call
…find_vacancies_in_date_range
…cies_in_date_range
HotelWhat We're Looking For
Good work overall. Your design for how to keep track of reservations is a little odd but it gets the job done, and experimenting with design is one of the goals for this project. It is important to me that you understand why I find it odd, and that you're comfortable dividing up responsibilities between classes - as is, everything landed in Outside of design, I like what I see. The code in your methods is generally well written. There are places where your test coverage could be expanded, but testing is a hard skill and takes a lot of practice to master. It would have been good to get to wave 3, but in terms of the fundamentals, it feels to me like you are in a good place. Keep up the hard work! |
# Method to list all reservation instances | ||
def list_reservations | ||
return @reservations | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does exactly the same thing as attr_reader :reservations
, just with a different name. In my mind, the attr_reader
meets the requirements here, and is a little cleaner.
lib/booking_manager.rb
Outdated
# Method to get total cost of reservation | ||
def get_reservation_cost(nights, cost_per_night) | ||
total_cost = nights * cost_per_night | ||
return total_cost |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Reservation
should have all the info about the number of nights and the cost per night, which indicates to me that this should be a method on the Reservation
, not on the BookingManager
. This is an example of not quite giving Reservation
a whole responsibility (which in turn means BookingManager
has more than one responsibility).
found_vacancies << room | ||
else | ||
info.any? {|date, reservation| date == search_date}? next : found_vacancies << room | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably not use a ternary here - it feels like too many things on one line.
end | ||
|
||
return found_vacancies.empty? ? no_vacancies_message: found_vacancies | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, it's considered bad practice to return a string in a failure case like this. One of the main reasons is that whoever calls this code will have to do a lot of work to determine whether or not it failed.
Instead you should either raise an exception, or (since this is supposed to return a collection) return an empty array. A simple implementation of the second option would be replacing line 143 with
return found_vacancies
lib/booking_manager.rb
Outdated
if reserved_dates.empty? | ||
rooms_available_in_date_range << room | ||
else | ||
date_range = determine_date_range(start_date, end_date) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the start date and end date don't change inside this loop, it would be a little more efficient to build the date_range
before the loop rather than inside it.
def determine_date_range(start_date, end_date) | ||
check_dates(start_date, end_date) | ||
|
||
res_start_date = Date.parse(start_date) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do a great job of using vertical whitespace (newlines) to break up the ideas in your code. This makes the whole program much easier to read.
def initialize(number_rooms) | ||
@rooms = populate_room_list(number_rooms) #(20) | ||
@reservations = make_reservation_list | ||
@room_calendar = make_room_calendar(number_rooms) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you've broken each of these initialization helpers out as separate methods - the pattern is very clear.
new_booking = "new reservation" | ||
|
||
@hotel_rooms.add_reservation(new_booking) | ||
expect(@hotel_rooms.reservations.length).must_equal old_number + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you check the old number first here.
describe "find_vacancies_on_date method" do | ||
before do | ||
@hotel = Hotel::BookingManager.new(5) | ||
room1 = @hotel.rooms[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a number of edge cases around when reservations overlap that you're missing here. A list was posted in slack at one point.
spec/booking_manager_spec.rb
Outdated
it "returns message of no vacancies when all rooms are reserved" do | ||
room4 = @hotel.rooms[3] | ||
room5 = @hotel.rooms[4] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this test! Good work covering this edge case.
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions