Conversation
HotelSection 1: Major Learning Goals
Section 2: Code Review and Testing Requirements
Section 3: Feature Requirements
Overall Feedback
Additional FeedbackGreat work overall! You've built your first project with minimal starting code. This represents an incredible milestone in your journey, and you should be proud of yourself! I am particularly impressed by the way that you organized your methods within your classes and made good use of Ruby's built-in methods. I do see some room for improvement around testing edge cases. Code Style Bonus AwardsWas the code particularly impressive in code style for any of these reasons (or more...?)
|
kaidamasaki
left a comment
There was a problem hiding this comment.
Great job! Here are a few little things that you can do to clean up your code even more. 😄
|
|
||
| #system | ||
|
|
||
| .DS_store |
There was a problem hiding this comment.
You can ignore .DS_Store everywhere by creating a global gitignore file.
| attr_reader :check_in, :check_out, :nights_spent | ||
|
|
||
| def initialize(check_in, check_out) | ||
| raise ArgumentError, 'Invalid date range given.' unless check_out > check_in |
There was a problem hiding this comment.
It's helpful to include the invalid arguments when you raise an ArgumentError.
| raise ArgumentError, 'Invalid date range given.' unless check_out > check_in | |
| raise ArgumentError, "Invalid date range given. check_in: #{check_in} check_out: #{check_out}" unless check_out > check_in |
| raise ArgumentError, 'Invalid date range given.' unless check_out > check_in | ||
| @check_in = check_in | ||
| @check_out = check_out | ||
| @nights_spent = (@check_out - @check_in) |
There was a problem hiding this comment.
Parenthesis here are unnecessary:
| @nights_spent = (@check_out - @check_in) | |
| @nights_spent = @check_out - @check_in |
| end | ||
|
|
||
| def to_id | ||
| return (@check_in.year.to_s + @check_in.mon.to_s + @check_in.mday.to_s) |
There was a problem hiding this comment.
You don't need parenthesis around return values:
| return (@check_in.year.to_s + @check_in.mon.to_s + @check_in.mday.to_s) | |
| return @check_in.year.to_s + @check_in.mon.to_s + @check_in.mday.to_s |
| end | ||
|
|
||
| def overlap? (other_check_in, other_check_out) | ||
| return ((@check_in..@check_out).cover? (other_check_in)) || ((@check_in-1...@check_out).cover? (other_check_out)) |
| # Parameters: | ||
| # -type: symbol (:SINGLE, :BLOCK) that indicates type of reservation | ||
| # -range: DateRange object | ||
| # -occupancy: Hash or String | ||
| # Returns: newly created Reservation object |
There was a problem hiding this comment.
I really like that you documented your parameters but it would be more helpful if you mentioned more than just the type but also what they represent.
Really the only confusing bit here is occupancy. Everything else is pretty self explanatory or well explained (like type).
| # Parameters: Date object | ||
| # Returns: an Array of all Reservation instances that contain that date | ||
| def find_reservations_by_date(check_in, check_out) | ||
| by_date = @reservations.select { |reservation| reservation.dates.overlap?(check_in, check_out)} |
There was a problem hiding this comment.
This works because of implicit return, but I don't think you meant to assign here (since you don't use the variable):
| by_date = @reservations.select { |reservation| reservation.dates.overlap?(check_in, check_out)} | |
| return @reservations.select { |reservation| reservation.dates.overlap?(check_in, check_out)} |
| end | ||
|
|
||
| def find_reservations_by_room(room) | ||
| by_room = @reservations.select { |reservation| reservation.occupancy.detect { |occupancy| occupancy[:room] == room }} |
There was a problem hiding this comment.
See above.
| by_room = @reservations.select { |reservation| reservation.occupancy.detect { |occupancy| occupancy[:room] == room }} | |
| return @reservations.select { |reservation| reservation.occupancy.detect { |occupancy| occupancy[:room] == room }} |
| it "populates valid room objects" do | ||
| expect(@reservation_manager.rooms[1]).must_be_kind_of Hotel::Room | ||
| end |
There was a problem hiding this comment.
A better check here would be to loop through all of the rooms with individual assertions:
| it "populates valid room objects" do | |
| expect(@reservation_manager.rooms[1]).must_be_kind_of Hotel::Room | |
| end | |
| it "populates valid room objects" do | |
| @reservation_manager.rooms.each do |room| | |
| expect(room).must_be_kind_of Hotel::Room | |
| end | |
| end |
| describe "create reservation" do | ||
| before do | ||
| @room = Hotel::Room.new(100) | ||
| @occupancy = [{:room => @room, :guest => "Picchu"}] |

Assignment Submission: Hotel
Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.
Reflection