Skip to content
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

Pipes - Kimberley Zell - Hotel #22

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
bf0a1dc
Wrote tests for Room in spec file. Wrote Room class file. Started wi…
kimpossible1 Sep 6, 2017
f43e787
Began creating Reservations class. Created self.all_rooms to generate…
kimpossible1 Sep 6, 2017
54a5c12
Fleshing out Booking class
kimpossible1 Sep 6, 2017
366a37e
created DateRange class file
kimpossible1 Sep 6, 2017
eca0b03
added tests for Booking class
kimpossible1 Sep 6, 2017
d4a5065
added tests and code for self.all_reservations method. Also added met…
kimpossible1 Sep 6, 2017
3518469
fixed method for new reservation and testing
kimpossible1 Sep 6, 2017
100c4c7
fixed/finished tests for all_reservations method
kimpossible1 Sep 6, 2017
49a2723
added total cost method to booking and tested with all reservations
kimpossible1 Sep 6, 2017
3c52875
working on Date Range class and way to get list of dates involved in …
kimpossible1 Sep 7, 2017
fc22026
updated DateRange class to include dates method to return an array of…
kimpossible1 Sep 7, 2017
59b5ae9
updated DateRange date method to create array of dates rather than st…
kimpossible1 Sep 7, 2017
5a3cab7
updated reservations with method to list reservations by date. Tests …
kimpossible1 Sep 7, 2017
0df26f0
changed all methods to instance methods. Now working on list reservat…
kimpossible1 Sep 7, 2017
5363e85
moved method dates from the date range class to the booking class and…
kimpossible1 Sep 7, 2017
b1b2b23
fixed DateRange dates method - it was not sending the dates to the ar…
kimpossible1 Sep 7, 2017
1284d13
moved def dates back to daterange.
kimpossible1 Sep 8, 2017
d5e1340
added class for InvalidDateError and added method within Booking to v…
kimpossible1 Sep 8, 2017
30aa6dd
corrected syntax error in tests for validate dates. tests now pass.
kimpossible1 Sep 8, 2017
8bde54c
Wrote method to check if room is available for dates given in reserva…
kimpossible1 Sep 8, 2017
0a93b75
made adjustments to auto assign room number method and to availabe me…
kimpossible1 Sep 8, 2017
2060ee8
Finally got method available working - gives argument error if a room…
kimpossible1 Sep 8, 2017
3f8d343
created tests on reservations. All passing. Started working on Blocks
kimpossible1 Sep 8, 2017
22cb829
updated Block class - it passes tests so far.
kimpossible1 Sep 9, 2017
616ecac
wrote methods in Reservations: new_block. Also created collection of …
kimpossible1 Sep 9, 2017
35c918d
Under Reservations class, new blocks can now be created with max 5 ro…
kimpossible1 Sep 9, 2017
6f77304
list rooms available by date will now exclude rooms in a block. Need…
kimpossible1 Sep 9, 2017
2b568e1
made a new method for checking if room is available, but tests are no…
kimpossible1 Sep 9, 2017
cab1b3a
In Reserations Class, rewriting methods or new methods for avail chec…
kimpossible1 Sep 10, 2017
7161af3
Added has_available_rooms? method to Block class and instance variabl…
kimpossible1 Sep 10, 2017
c4d5974
removed variable to determine if a reservation is a block booking - d…
kimpossible1 Sep 10, 2017
5a86dc6
check availability method updated but tests still failing. Tests upda…
kimpossible1 Sep 10, 2017
af5228a
Found problem with availability. Had to move it to after the Booking …
kimpossible1 Sep 10, 2017
88d15c4
In Reservations class, have basic method for make a new reservation i…
kimpossible1 Sep 10, 2017
a0d858f
in block method now working under Reservations Class. It checks that …
kimpossible1 Sep 10, 2017
9127e71
All methods so far working except if room is not in block is failing …
kimpossible1 Sep 10, 2017
c08170d
Added validate dates in Reservations class to make sure dates of new …
kimpossible1 Sep 11, 2017
0b64991
added a method match_block to quickly find which block the new reserv…
kimpossible1 Sep 11, 2017
cd21027
corrected spec files to be separate by class
kimpossible1 Sep 11, 2017
02fc0e9
completed design activity questions
kimpossible1 Sep 29, 2017
bef0655
Trying to clean up the mess from trying to rework this code...
kimpossible1 Oct 2, 2017
1d6fca5
cleaned up the reservations class - moved some functions to Block cla…
kimpossible1 Oct 2, 2017
f468b3e
Corrected file names but now rake not working. Have corrected filenam…
kimpossible1 Oct 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions Rakefile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs = ["lib"]
t.warning = true
t.test_files = FileList['specs/*-specs.rb']
end

task default: :test
81 changes: 81 additions & 0 deletions design-activity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#What classes does each implementation include? Are the lists the same?

Implementation A includes the following classes:
CartEntry, ShoppingCart, Order

Implementation B includes the following classes:
CartEntry, ShoppingCart, Order

The lists are the same.

#Write down a sentence to describe each class.

CartEntry adds an item to cart with the quantity and unit price.

ShoppingCart holds a list of all items added to the cart.

Order creates a new instance of ShoppingCart and can calculate the total price of the cart.


How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper.

An Order holds a ShoppingCart and its price. A ShoppingCart holds all items entered for that cart. A CartEntry is used to create entries that will be added to the ShoppingCart.

What data does each class store? How (if at all) does this differ between the two implementations?

In A and B, CartEntry stores the unit price and quantity for an item.

In A and B, ShoppingCart stores a list of entries.

In A and B, Order stores SALES_TAX and a ShoppingCart.

What methods does each class have? How (if at all) does this differ between the two implementations?

A has the following methods for each class:
CartEntry: initialize
ShoppingCart: initialize
Order: initialize, total_price

B had the following:
CartEntry: initialize, price
ShoppingCart: initialize, price
Order: initialize, total_price

B has a method to calculate price for each class, rather than only one as in A.


Consider the Order#total_price method. In each implementation:

Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order?
In B the logic to compute price is contained in lower level classes, but in A it is not - in A it is retained in Order.

Does total_price directly manipulate the instance variables of other classes?

In A it does.

If we decide items are cheaper if bought in bulk, how would this change the code?

In A it would be harder to change because we do not calculate price for each item separately in A.

In B it would be easier to change, because we could add code to give an item discount when bought in bulk in the CartEntry class. Since price is calculated for each item in CartEntry, the other classes would not be affected or have knowledge of this change.

Which implementation is easier to modify?

B is easier to modify.

Which implementation better adheres to the single responsibility principle?

B adheres better.

Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled?

B is more loosely coupled.

# Identify one place in your Hotel project where a class takes on multiple roles, or directly modifies the attributes of another class.
The Reservations class directly modifies attributes of other classes and overreaches in responsibility. The other classes stick to single responsibility but Reservations does not and is much more complicated. Reservations is too tightly coupled with other classes in several methods.

# Describe in design-activity.md what changes you would need to make to improve this design, and how why the resulting design would be an improvement.

I would remove direct calls on other classes in the methods as much as possible, and instead create instance variables on initialize within Reservations. I would move as much as possible of the date checking, availability checking, date range creation, etc to the DateRange class. I would have DateRange initialize with an array of dates rather than needing to call that method on a date range each time I need it.

This would be an improvement because it would make the program more resilient to breaking if changes are made to other classes. It would also make the code easier and less complicated to change in the future.
Binary file added lib/.DS_Store
Binary file not shown.
62 changes: 62 additions & 0 deletions lib/Block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

module Hotel
class Block < DateRange
attr_accessor :check_in, :check_out, :date_range, :dates, :block_rooms_collection, :discounted_room_rate, :available_rooms, :booked, :block_name, :number_of_rooms

def initialize(check_in, check_out, block_name, block_rooms_collection = [], discounted_room_rate = 180)

@check_in = Date.parse(check_in)
@check_out = Date.parse(check_out)
@date_range = Hotel::DateRange.new(check_in, check_out)
@dates = @date_range.dates
# @dates = Hotel::DateRange.new(@check_in, @check_out).dates
@block_rooms_collection = block_rooms_collection
@discounted_room_rate = discounted_room_rate
@booked = []
@block_name = block_name
# @number_of_rooms = number_of_rooms
# create_block_rooms_collection
# Hotel::Reservations.blocks_collection << Self
end

# def create_block_rooms_collection
# unless @number_of_rooms <= 5 && @number_of_rooms >= 1
# raise ArgumentError.new("Blocks can only have between 1 and 5 rooms.")
# end
# rooms_available = Hotel::Reservations.rooms_collection
# @dates.each do |date|
# Hotel::Reservations.list_reservations_by_date(date).each do |booking|
# rooms_available.each do |room|
# if room.room_number == booking.room_number
# rooms_available.delete(room)
# end
# end
# end
# end
# @block_rooms_collection = []
#
# @number_of_rooms.times do |i|
# @block_rooms_collection << rooms_available[i]
# end
# return @block_rooms_collection
# end

def validate_block_dates(check_in, check_out, block)
if check_in >= block.check_in && check_out <= block.check_out
return true
else
raise ArgumentError.new("Cannot reserve for those dates - dates must be the same as block dates.")
end
end

def has_rooms_available?
if !(@booked.length < @block_rooms_collection.length)
return false
else
return true
end
end


end
end
64 changes: 64 additions & 0 deletions lib/Booking.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require 'date'
require 'DateRange'

module Hotel


class Booking < DateRange
attr_reader :check_in, :check_out, :room_number, :date_range
def initialize(check_in, check_out, room_number = rand(1..20), room_rate = 200)
@room_number = room_number
@check_in = Date.parse(check_in)
@check_out = Date.parse(check_out)
@date_range = DateRange.new(check_in, check_out)
@dates = @date_range.dates
@room_rate = room_rate
#@dates = Hotel::DateRange.new(check_in, check_out)
# @num_days = (@check_out - @check_in).to_i
# @total_cost = (@room_rate * @num_days)
@discount = 0

# validate_dates
end

# def validate_dates
# unless @check_in >= Date.today
# raise InvalidDateError.new("Check-in cannot be before today's date.")
# end
# unless @check_in < @check_out
# raise InvalidDateError.new("Check-in cannot be after check-out.")
# end
# end

def total_cost
num_days = (@check_out - @check_in).to_i
total_cost = @room_rate * num_days
return total_cost
end
end

end

# def available
# # greater than or equal than check_in date
# # and less than or equal to check_out date
# #
# # if the reservation dates contains the check_in date of an existing reservation it's already aproblem?
# @dates[0...-1].each do |date|
# list = Hotel::Reservations.list_reservations_by_date(date)
# list.each do |booking|
# if booking.room_number == room_number
# raise ArgumentError.new("Room number #{room_number} is not available for those dates.")
# end
# end
# end
# end


# def valid_dates
#
# unless card_is_valid?(card_number)
# raise InvalidCardNumberError.new("Invalid credit card number #{card_number}")
# end
# # ... process the transaction ...
# end
Loading