-
Notifications
You must be signed in to change notification settings - Fork 48
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
Ports - Elle #38
base: master
Are you sure you want to change the base?
Ports - Elle #38
Conversation
…w passing. Ready to start writing code.
…ss and Manager class. Created tests for creation of rooms array. Generally got this much working.
…st of the reservation. Wrote tests for same. All passing.
…ed), and add the reseveration object to the array associated with (value of) the room number's key in rooms_reservations_hash. Test added for same, passing.
…urn a list (array) of rooms that have a reservation on that date. Along with the room number, the full date range of the reservation is returned.
…e range'. It's failing as desired.
…te range' test. The find_avail_fooms_for_dates method searches each array of reservations to find gaps between bookings and adds the associated available room number to an array, which is returned.
…e other small adjustments to clean up comments.
…ates. This is broken out of the previous function to allow for use in multiple places. Also added checks for 0 and 1 item arrays, as well as checking for availability before first reservation or after last reservation.
…eing added to the available rooms array. Everything else is working. Next: delete some things and re-write them.
… now see a list of rooms that are not reserved for a given date range, reserve an available room, and get an exception error when trying to make a reservation for an unavailable room. Need to build out more tests to check edge cases.
…both for raising exceptions and for making reservations with shared check-in/check-out dates. (Wave 2 complete.)
HotelWhat We're Looking For
|
|
||
def self.make_rooms | ||
rooms_res_hash = {} | ||
(1..NUM_OF_ROOMS).each { |i| rooms_res_hash[i] = [] } |
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.
Interesting a hash of rooms with the number being the key, and the value being an array of reservations. Nice!
attr_accessor :rooms_reservations_hash | ||
|
||
def initialize | ||
@rooms_reservations_hash = Room.make_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 having this class method in Room. However since you never make an instance of the Room class, maybe instead make Room a module, or have make_rooms
as a private factor method in Manager
.
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.
Thanks Chris. Room actually is a module! :-D It's in the room.rb file. Is this an acceptable setup or would it be better to eliminate the room.rb file and move that code into manager.rb?
I like having this class method in Room. However since you never make an instance of the Room class, maybe instead make Room a module, or have
make_rooms
as a private factor method inManager
.
end | ||
end | ||
|
||
return res_on_date # array with [[1, "2019-06-10 through 2019-06-12"], [room_num, "date through date"], etc] |
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 works, but I'd suggest that it would be easier as an array of hashes with the keys room
and reservation_date
, just for readability.
lib/manager.rb
Outdated
(res_0.ckout_date <= ckin) || (ckout <= res_0.ckin_date) ? true : false | ||
else # there is more than one reservation in the array | ||
# check left and right ends of the reservation array | ||
return true if (ckout <= res_0.ckin_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.
Your code maintains your reservations listed in order, later if you take advantage of things Shruti will teach you like binary search some actions like finding a reservation or finding overlapping reservations may be more efficient.
Nice
return avail_rooms | ||
end | ||
|
||
def print_available_rooms_for_dates(ckin, ckout) |
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 the future I'd recommend that you separate the roles of printing information and managing rooms and reservations. Printing things out is something I'd do in a driver method or class.
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.
Hi Chris, are you talking about lines 75 & 76? I think those were a couple of puts statements that I was using to test/debug and just forgot to comment them out. My print method is directly below, starting on line 87. Is this what you mean, or am I still missing a concept? I think you might be saying that my Manager class is currently acting as a driver class as well as validating the availability of the reservation dates.
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 method print_available_rooms_for_dates
is doing printing that should probably be pulled into a separate module
return avail_rooms | ||
end | ||
|
||
def get_insert_index(res_array, new_res) |
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.
Just a note for CS Fun. You could speed this up with a binary search. Something to remember.
module Hotel | ||
class Reservation | ||
attr_reader :ckin_date, :ckout_date, :date_range_string_array, :num_nights_of_stay, :base_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.
Consider moving the checking for overlapping a date with the reservation to this class, so it could handle more actions that deal with a specific reservation. It might simplify your manager class.
Also calculating the cost of a reservation is probably best done as a method just in case the dates change (extremely minor point).
expect(this_manager.rooms_reservations_hash[9][0].ckin_date.to_s).must_equal "2019-05-29" | ||
end | ||
|
||
it "Reservation is allowed if check in or check out is same as another reservation's check in or check out date" do |
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.
Good test! 👍
…t doesn't exist'.
…nto Reservation in order to decouple. Pulled the length of stay and cost calculations out of the initialize method and into instance methods. Also renamed self.get_date_conflicts to self.ck_dates_are_available for clarity and increased intuition about what is returned.
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions