Conversation
HotelWhat We're Looking For
|
| class Block | ||
| attr_reader :start_date, :end_date, :room_collection, :discount_rate | ||
|
|
||
| def initialize(start_date:, end_date:, room_collection: [], discount_rate: 0.8) |
There was a problem hiding this comment.
I would have liked to see Block use a DateRange object internally instead of just having a start and end date.
| @@ -0,0 +1,24 @@ | |||
| module HotelManagementSystem | |||
| class DateRange | |||
| def self.is_valid?(start_date, end_date) | |||
There was a problem hiding this comment.
I'd like to see this turned into a constructor that raises since a date range is a thing you can perform meaningful operations on.
| @blocks = [] | ||
|
|
||
| 1..20.times do |i| | ||
| room = HotelManagementSystem::Room.new(room: i + 1) |
There was a problem hiding this comment.
Ruby will be looking for names locally first, prioritizing local names, since they're all in the same module, there's no need to namespace Hotel::Room. Room should just work! Same with the rest of the namespacing in the code.
| end | ||
|
|
||
| def reserve(start_date, end_date) | ||
| if !HotelManagementSystem::DateRange.is_valid?(start_date, end_date) |
There was a problem hiding this comment.
You can use unless to make this a little clearer.
| if !HotelManagementSystem::DateRange.is_valid?(start_date, end_date) | |
| unless HotelManagementSystem::DateRange.is_valid?(start_date, end_date) |
|
|
||
| # assigns first available room to reservation | ||
| room_assignment = list_available_rooms(start_date, end_date).first | ||
| raise ArgumentError, "There is no room available for these dates." if room_assignment == nil |
There was a problem hiding this comment.
Very slightly cleaner.
| raise ArgumentError, "There is no room available for these dates." if room_assignment == nil | |
| raise ArgumentError, "There is no room available for these dates." unless room_assignment |
| end | ||
|
|
||
| def cost_of_block(block) | ||
| block = @blocks.find{|i| i == block} |
There was a problem hiding this comment.
I think all this line does is give you back nil if block isn't in @blocks.
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions