Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
bff8a29
File structure setup
pmanni02 Mar 5, 2018
f6c8bd4
Adds #initialize and related tests
pmanni02 Mar 5, 2018
ac8bb70
Adds #create_rooms and related tests
pmanni02 Mar 5, 2018
0356e37
Deletes .keep files
pmanni02 Mar 5, 2018
0b1d255
Adds #initialize and tests
pmanni02 Mar 5, 2018
b01730b
Refactors #create_rooms and tests in Admin class
pmanni02 Mar 5, 2018
4afaa05
Changes 'FALSE' to 'false' in #initialize in Room class and tests
pmanni02 Mar 5, 2018
c4d9aa4
Injects dependency -> #create_room_instance and tests
pmanni02 Mar 5, 2018
6b1c294
Refactors #create_room_instance and tests to account for invalid input
pmanni02 Mar 5, 2018
e253e40
Adds #create_reservation & #check_reservation data to Admin class + r…
pmanni02 Mar 5, 2018
efb6dc7
Changes from #check_reservation_data(reservation_data) to #check_date…
pmanni02 Mar 5, 2018
d953dc4
Adds #initialize and related tests in Reservation class
pmanni02 Mar 5, 2018
3621433
Adds new #create_reservation and tests & changes previously made meth…
pmanni02 Mar 5, 2018
40f34bb
Pushes new reservation instance into @reservations array
pmanni02 Mar 6, 2018
502b2e0
Adds cost calculation to Admin class & modifies related test and Rese…
pmanni02 Mar 6, 2018
e2819d6
Fixes total_days var
pmanni02 Mar 6, 2018
959094f
Comments out reservation id var and test
pmanni02 Mar 6, 2018
72b915c
tests for and template of #get_reservation_list
pmanni02 Mar 6, 2018
cd52adc
#compare dates and tests
pmanni02 Mar 6, 2018
4b7464e
Completes #get_reservation_list(date) and tests in Admin class
pmanni02 Mar 6, 2018
2d59cfa
removes #create_reservation in Admin & creates #calculate_cost in Res…
pmanni02 Mar 6, 2018
54e648d
adds edge case for #calculate_cost
pmanni02 Mar 6, 2018
2770088
Changes is_reserved instance variable from false to true
pmanni02 Mar 7, 2018
7a73903
Adds template for #get_unreserved_rooms and tests
pmanni02 Mar 7, 2018
8ca6c0e
Adds room as parameter for #add_reservation
pmanni02 Mar 7, 2018
88ce651
Tests for #get_unreserved_rooms
pmanni02 Mar 7, 2018
abc98fe
Modifies #compare_dates, #get_reservation_list, and related tests in …
pmanni02 Mar 7, 2018
cbcd63a
Changes reservation class to have a Room class instance instead of a …
pmanni02 Mar 7, 2018
007f1b9
Adds new parameter is_available to room Class
pmanni02 Mar 7, 2018
81984d4
Modifies #add_reservation to change is_reserved variable
pmanni02 Mar 7, 2018
4ec6442
Refactors and adds tests for #get_unreserved_rooms
pmanni02 Mar 7, 2018
7c91037
Raises standard error if reservation is requested for unavailable roo…
pmanni02 Mar 7, 2018
251340a
Changes return values for #compare_dates
pmanni02 Mar 7, 2018
163009b
Cleans and refactors Admin class and tests
pmanni02 Mar 8, 2018
b0831a9
Refactors and cleans Reservation class
pmanni02 Mar 8, 2018
3b57b85
Refactors and cleans Room class and tests
pmanni02 Mar 8, 2018
683c9de
Changes local var unreserved_rooms to unreserved_rooms_ids in #get_un…
pmanni02 Mar 8, 2018
ce52353
Changes #calculate_cost in Reservation class
pmanni02 Mar 8, 2018
9bb863d
Removes require 'time'
pmanni02 Mar 8, 2018
0de6bfb
Adds method stubs/pseudocode/todos for Wave 3 requirements
pmanni02 Mar 9, 2018
53de683
Adds test stubs/comments for existing methods before Wave 3 changes
pmanni02 Mar 9, 2018
b0176f3
Pre-wave 3 clean up
pmanni02 Mar 9, 2018
b1b9e04
Adds is_in_block instance variable to Room class
pmanni02 Mar 9, 2018
cba162f
Adds is_in_block logic to existing methods
pmanni02 Mar 9, 2018
9791736
Creates default value for @cost_per_night and @cost to @total_cost
pmanni02 Mar 9, 2018
ca848b7
Adds test for #total_cost using non-default cost_per_night val
pmanni02 Mar 9, 2018
7db56fb
Adds @base_rate, @discount_rate, #cost_per_night
pmanni02 Mar 9, 2018
13c39ee
Adds tests for @base_rate and @discount_rate. Adds comments for futur…
pmanni02 Mar 9, 2018
c99a49a
Adds #get_room(id) helper method
pmanni02 Mar 9, 2018
f5ba6e7
Adds #check_rooms(array_of_rooms) and test
pmanni02 Mar 9, 2018
a5b991d
Adds #check_reservations(date_range, reservations) and test
pmanni02 Mar 9, 2018
8f11854
Adds @blocks in Admin class and adds one test
pmanni02 Mar 9, 2018
1c46182
Adds #make_block and related tests
pmanni02 Mar 9, 2018
406579a
Adds private #get_room_objs
pmanni02 Mar 9, 2018
bf6e31e
Adds test in #get_unreserved_rooms for blocks
pmanni02 Mar 9, 2018
63a5582
Adds #get_block(room_id) and tests
pmanni02 Mar 10, 2018
afef755
Adds #add_reservation_in_block and related tests
pmanni02 Mar 11, 2018
dc1e7c2
Adds #check_block(block) and tests
pmanni02 Mar 11, 2018
6f6ea54
Refactors tests
pmanni02 Mar 11, 2018
07ad4c3
Code/comment cleanup and #check_block refactor
pmanni02 Mar 11, 2018
33aa7f3
Adds conditional to #make_block and creates related test
pmanni02 Mar 11, 2018
c4bc028
Fixes get_unreserved_rooms in Admin
pmanni02 Mar 12, 2018
b22fad9
Initial hotel cli
pmanni02 Mar 12, 2018
d895a9b
Fixes get_unreserved_rooms
pmanni02 Mar 12, 2018
8764a52
Updated but incomplete cli
pmanni02 Mar 12, 2018
5ea8cab
Deletes #check_rooms
pmanni02 Mar 12, 2018
33e93a5
Deletes #check_rooms
pmanni02 Mar 12, 2018
cb2af26
Code clean up
pmanni02 Mar 12, 2018
bf9eba4
removes local variables as suggested
pmanni02 Mar 25, 2018
7cacac9
design-activity
pmanni02 Mar 28, 2018
c0366b5
adds methods to Room class to handle variable manipulation
pmanni02 Mar 28, 2018
17e73d8
code cleanup
pmanni02 Mar 28, 2018
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
9 changes: 9 additions & 0 deletions Rakefile
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/*_spec.rb']
end

task default: :test
34 changes: 34 additions & 0 deletions design-activity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
1. What classes does each implementation include? Are the lists the same?
Each implementation has a CartEntry, ShoppingCart, and Order class.

2. Write down a sentence to describe each class.
The CartEntry class is responsible for the individual item(s) inside the shopping cart.

The ShoppingCart class is responsible for all of the items in the shopping cart (instances of CartEntry).

The Order class is responsible for one instance of a shopping trip (shopping cart).

3. How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper.
The Order class contains one instance of the ShoppingCart class. The ShoppingCart class contains an array of CartEntry class instances.

4. What data does each class store? How (if at all) does this differ between the two implementations?
For both implementations, the CartEntry class contains the unit price and quantity of a cart item. The ShoppingCart class contains an array of CartEntry instances. The Order class contains an instance of the ShoppingCart class and a Sales_Tax constant variable.

5. What methods does each class have? How (if at all) does this differ between the two implementations?
All of the classes have initialize methods. In implementation A, the Order class has a total_price method. In implementation B, all three classes have price methods.

6. Consider the Order#total_price method. In each implementation:
a. Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order?
In implementation A, the logic to compute price is retained in the Order class. In implementation B, the logic to compute price is delegated to lower level classes.

b. Does total_price directly manipulate the instance variables of other classes?
In implementation A, the total_price method does manipulate instance variables of other classes. In implementation B, the total_price method does not directly manipulate instance variables. The instance variables of other classes are manipulated through class methods.

7. If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify?
In order to implement this change, a new method would have to be added to the CartEntry class to contain the logic for changing the price based on quantity. It would be easier to change implementation B because it already contains a price method.

8. Which implementation better adheres to the single responsibility principle?
Implementation B better adheres to the single responsibility principle because the logic of calculating the total cost is passed off to "lower level" classes. The Order class, in implementation B, calls the methods of other classes instead of directly manipulating instance variables.

9. Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled?
Implementation B is more loosely coupled because each of the classes have less dependency. In implementation A, the data in the CartEntry and ShoppingCart classes are not useful without the Order class. But in implementation B, the CartEntry and ShoppingCart classes do not necessarily need the Order class. They are still dependent on each other but not as dependent as in implementation A.
171 changes: 171 additions & 0 deletions hotel_cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
require 'pry'

require_relative 'lib/admin'
require_relative 'lib/reservation'
require_relative 'lib/room'

HOTEL = Hotel::Admin.new

def display_options
puts
puts "----------------- OPTIONS ----------------"
puts "SHOW all reservations - reservations OR 1"
puts "ADD reservation - add reservation OR 2"
puts "SHOW all blocks - blocks OR 3"
puts "ADD block - add block OR 4"
puts "To exit this program - exit"
puts "------------------------------------------"
puts "OPTION: "
puts
end

def show_rooms(rooms)
i = 0
while i < rooms.length
print "\nRoom ID: #{rooms[i].room_id} | "
print "Reserved?: #{rooms[i].is_reserved.to_s} | "
print "In block?: #{rooms[i].is_in_block.to_s}"
i += 1
end
puts
end

def show_reservations(reservations)
if reservations.length == 0
puts "\nThere are no current reservations."
else
i = 0
while i < reservations.length
print "\nRoom ID: #{reservations[i].room.room_id} | "
print "Start Date: #{reservations[i].start_date} | "
print "End Date: #{reservations[i].end_date} | "
print "Cost per night: #{reservations[i].cost_per_night} | "
print "Total Cost: #{reservations[i].total_cost}"
i += 1
end
puts
end
end

def valid_input_loop(pattern)
input = gets.chomp
while !pattern.match(input)
puts "Please enter info in the valid format."
input = gets.chomp
end
return input
end

def get_date_range
pattern = /^\d{4}\-\d{2}\-\d{2}$/
valid_date = false
until valid_date == true
date_range = {}
puts "Please enter start date in the following format -> yyyy-mm-dd: "
start_date_input = valid_input_loop(pattern)
start_date = Date.strptime( start_date_input, '%Y-%m-%d')
date_range[:start_date] = start_date
puts "Please enter end date in the following format -> yyyy-mm-dd: "
end_date_input = valid_input_loop(pattern)
end_date = Date.strptime( end_date_input, '%Y-%m-%d')
date_range[:end_date] = end_date
if HOTEL.check_date_range(date_range)
valid_date = true
else
puts "Invalid date range - try again"
end
end
return date_range
end

def show_available_rooms(date_range)
puts "\nThe following rooms are available for reservation: "
available_rooms = HOTEL.get_unreserved_rooms(date_range)
available_rooms.each do |room|
print "#{room} | "
end
puts
return available_rooms
end

def show_reservation(reservation)
puts " - Start Date: #{reservation.start_date}"
puts " - End Date: #{reservation.end_date}"
puts " - Room ID: #{reservation.room.room_id}"
puts
end

def get_reservation
date_range = get_date_range
available_rooms = show_available_rooms(date_range)

puts "\nPlease enter an available room ID"
pattern = /^[1-9]{1}[0-9]{0,1}$/
room_id = valid_input_loop(pattern).to_i
until room_id <= HOTEL.num_rooms && room_id > 0 && available_rooms.include?(room_id)
puts "\nInvalid room ID"
show_available_rooms(date_range)
room_id = valid_input_loop(pattern).to_i
end

return HOTEL.add_reservation(date_range, room_id)
end

def show_block(block)
puts " - Start Date: #{block[:start_date]}"
puts " - End Date: #{block[:end_date]}"
puts " - Rooms: "
rooms = block[:rooms]
rooms.each do |room|
print "#{room.room_id} | "
end
puts " - Cost/Night: $#{block[:room_rate]}"
end

def get_block
date_range = get_date_range
# available_rooms = show_available_rooms(date_range)
puts "\nPlease enter # of rooms in block [1-5]."
pattern = /^[1-5]{1}/
num_rooms = valid_input_loop(pattern).to_i
return HOTEL.make_block(date_range, num_rooms)
end

puts "Welcome to [insert name here] Hotel!"
puts "\n--------------- HOTEL INFO ---------------"
puts "Number of rooms: #{HOTEL.num_rooms}"
puts "Base room rate: #{HOTEL.base_rate}"
puts "Discount rate/room for block reservation: #{HOTEL.discount_rate * 100}%"
puts

display_options
command = gets.chomp

while command != "exit"
if command == "reservations" || command == "1"
show_reservations(HOTEL.reservations)
elsif command == "add reservation" || command == "2"
reservation = get_reservation
puts "\nReservation Complete!"
show_reservation(reservation)
elsif command == "blocks" || command == "3"
if HOTEL.blocks.length == 0
puts "There are no blocks"
else
HOTEL.blocks.each do |block|
show_block(block)
puts
end
end
puts
elsif command == "add block" || command == "4"
block = get_block
puts "\nBlock Complete!"
show_block(block)
else
puts "Please enter a valid command."
end
puts
display_options
command = gets.chomp
end
Empty file removed lib/.keep
Empty file.
Loading