From 7acc0722d49b4d196ec3b12212640511dcc0b084 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 11:17:57 -0700 Subject: [PATCH 01/87] Added simplecov to spec_helper.rb --- spec/spec_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d1e3fdc8..d7ca189bf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,9 @@ +require 'simplecov' +SimpleCov.start require 'minitest' require 'minitest/autorun' require 'minitest/reporters' -# Add simplecov + Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 308e03fd33cee3bf1c5fb2ccc22f79a0823ef1d6 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 11:36:47 -0700 Subject: [PATCH 02/87] Edited spacing between require elements in spec_helper --- spec/spec_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d7ca189bf..f5a67a7f5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ require 'simplecov' SimpleCov.start + require 'minitest' require 'minitest/autorun' require 'minitest/reporters' From 7230317ed9458568271136e1aa2c122b7f94960c Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 11:37:37 -0700 Subject: [PATCH 03/87] Added hotel.rb file --- lib/hotel.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 lib/hotel.rb diff --git a/lib/hotel.rb b/lib/hotel.rb new file mode 100644 index 000000000..7d08db7cc --- /dev/null +++ b/lib/hotel.rb @@ -0,0 +1,3 @@ +def hotel + return "hotel" +end From 89ea0f19a0230c9cbb058fae79837117fb3ec384 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 11:38:25 -0700 Subject: [PATCH 04/87] Added hotel_spec.rb --- spec/hotel_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 spec/hotel_spec.rb diff --git a/spec/hotel_spec.rb b/spec/hotel_spec.rb new file mode 100644 index 000000000..74e836e9d --- /dev/null +++ b/spec/hotel_spec.rb @@ -0,0 +1,9 @@ +require_relative 'spec_helper' + +describe 'hotel' do + + it 'returns the string "hotel"' do + result = hotel() + expect(result).must_equal "hotel" + end +end From 8e0c9de2168f1d697d6c61cc7ebf3bbe1908255f Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 14:21:35 -0700 Subject: [PATCH 05/87] Edited first line of Guardfile to be compatible with simplecov gem --- Guardfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Guardfile b/Guardfile index 6760f9177..fa59fc3ef 100644 --- a/Guardfile +++ b/Guardfile @@ -1,4 +1,4 @@ -guard :minitest, bundler: false, rubygems: false do +guard :minitest, bundler: false, autorun: false, rubygems: false do # with Minitest::Spec watch(%r{^spec/(.*)_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } From 3d424bf05f379858e681c27a587760231952ce9b Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 14:37:29 -0700 Subject: [PATCH 06/87] Created room class --- lib/room.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/room.rb diff --git a/lib/room.rb b/lib/room.rb new file mode 100644 index 000000000..bee3f1889 --- /dev/null +++ b/lib/room.rb @@ -0,0 +1,10 @@ + +module Hotel + class Room + + def room + return "room" + end + + end # end of class Room +end # end of Module From f1954c1f2168c2dafdd13ec157b2cd80764beda5 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 14:38:14 -0700 Subject: [PATCH 07/87] Created booking_manager class for administrator User stories --- lib/booking_manager.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/booking_manager.rb diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb new file mode 100644 index 000000000..e69de29bb From 25e3199abf2662c54552e6b7aa4b17d7ebe1fbf5 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 14:52:22 -0700 Subject: [PATCH 08/87] Deleted hotel.rb --- lib/hotel.rb | 3 --- spec/room_spec.rb | 12 ++++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) delete mode 100644 lib/hotel.rb create mode 100644 spec/room_spec.rb diff --git a/lib/hotel.rb b/lib/hotel.rb deleted file mode 100644 index 7d08db7cc..000000000 --- a/lib/hotel.rb +++ /dev/null @@ -1,3 +0,0 @@ -def hotel - return "hotel" -end diff --git a/spec/room_spec.rb b/spec/room_spec.rb new file mode 100644 index 000000000..e4d78ed3c --- /dev/null +++ b/spec/room_spec.rb @@ -0,0 +1,12 @@ +require_relative 'spec_helper' + +describe "Room class" do + + describe "Initializer" do + it "is an instance of Room" do + number = 2 + @room = Hotel::Room.new(number) + expect(@room).must_be_kind_of Hotel::Room + end + end +end From 78e00656af98aeee5a34025af3332e9db080ba11 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 14:53:02 -0700 Subject: [PATCH 09/87] Deleted hotel_spec.rb --- spec/hotel_spec.rb | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 spec/hotel_spec.rb diff --git a/spec/hotel_spec.rb b/spec/hotel_spec.rb deleted file mode 100644 index 74e836e9d..000000000 --- a/spec/hotel_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require_relative 'spec_helper' - -describe 'hotel' do - - it 'returns the string "hotel"' do - result = hotel() - expect(result).must_equal "hotel" - end -end From 9c891a6a5ebef7b92df6247af1659a823d6a58d1 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 14:54:23 -0700 Subject: [PATCH 10/87] Added module Hotel to class Room and created Room#initialize --- lib/room.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index bee3f1889..9195270b7 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,10 +1,11 @@ module Hotel class Room + attr_reader :number - def room - return "room" + def initialize(number) + @number = number end - end # end of class Room -end # end of Module + end # of class Room +end # of module Hotel From 650f522cabb472cece17d8c84c0b470e9a3aa1ca Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 15:11:19 -0700 Subject: [PATCH 11/87] Added pseudocode to class BookingManager for methods to populate room list, list rooms, list reservations, get cost --- lib/booking_manager.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index e69de29bb..032b4b6eb 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -0,0 +1,29 @@ +require_relative 'room' + +module Hotel + class BookingManager + attr_accessor :rooms, :reservations + + def initialize + @rooms = list_rooms + @reservations = list_reservations + end # of def initialize + + # Create list of rooms as list of room Instances + def populate_room_list + + end + + # Method to list all rooms in hotel + # def list_rooms + # @rooms + # end + + # Method to list all reservations + # def list_reservations + # end + + # Method to get total cost of reservation + + end # of class BookingManager +end # of module Hotel From a8c928fdf4db1f79d93ddc9c4bd43b7482da5894 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 15:26:08 -0700 Subject: [PATCH 12/87] Added BookingManager#populate_room_list to create list of hotel rooms --- lib/booking_manager.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 032b4b6eb..c4338f348 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -5,14 +5,21 @@ class BookingManager attr_accessor :rooms, :reservations def initialize - @rooms = list_rooms - @reservations = list_reservations + @rooms = populate_room_list + @reservations = reservations end # of def initialize # Create list of rooms as list of room Instances - def populate_room_list + def populate_room_list(number_rooms) + rooms = [] + num = 1 - end + number_rooms.times do |room| + room = Room.new(num) + rooms << room + num += 1 + end # of number_rooms loop + end # of populate_room_list method # Method to list all rooms in hotel # def list_rooms @@ -24,6 +31,6 @@ def populate_room_list # end # Method to get total cost of reservation - + end # of class BookingManager end # of module Hotel From 127b6cbfaa37735058c40e51a805b97af8759259 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 15:36:13 -0700 Subject: [PATCH 13/87] Added instance variable for availabiity and Room#check_availability pseudocode --- lib/room.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/room.rb b/lib/room.rb index 9195270b7..1fb175c34 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,11 +1,22 @@ +require_relative 'booking_manager' module Hotel class Room attr_reader :number + attr_accessor :availability def initialize(number) - @number = number + @number = number.to_i + @availability = check_availability end + def check_availability(start_date, end_date) + # Do..something with dates. + # if date of check is within range + # return boolean + availability = true + return availability + end # of check_availability + end # of class Room end # of module Hotel From 5a6f954ec96e33f80bdcc761e184c653aa8745c2 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 15:40:33 -0700 Subject: [PATCH 14/87] Added booking_manager_spec --- spec/booking_manager_spec.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 spec/booking_manager_spec.rb diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb new file mode 100644 index 000000000..e69de29bb From 8602647dad2d98c38900599242e35631e7d3522e Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 15:41:26 -0700 Subject: [PATCH 15/87] Added require relative booking manager to spec_helper --- spec/spec_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f5a67a7f5..ba44ea20e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,3 +9,7 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # Require_relative your lib files here! +require_relative '../lib/room.rb' +require_relative '../lib/booking_manager.rb' + +# require_relative '..' From fcceb7b659ebc5fed7197f2ac1678a1e219d0a74 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 16:25:19 -0700 Subject: [PATCH 16/87] Added tests for BookingManager instantiation --- spec/booking_manager_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index e69de29bb..ee24e9618 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -0,0 +1,21 @@ +require_relative 'spec_helper' + +describe "BookingManager class" do + describe "Initializer" do + it "is an instance of BookingManager" do + manager = Hotel::BookingManager.new + expect(manager).must_be_kind_of Hotel::BookingManager + end # of it instance bookingmanager + + it "creates the proper structures for instance variables instantiated" do + hotel_rooms = Hotel::BookingManager.new + + expect (hotel_rooms.rooms).must_be_kind_of Array + expect (hotel_rooms.reservations).must_be_kind_of Array + end + end # of initializer describe + + + + +end # end of describe BookingManager class From 5a0c061c69ec1c7f31333c958e34d34dc197d951 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 17:01:49 -0700 Subject: [PATCH 17/87] Added method to make reservation list for instantiation of @reservations --- lib/booking_manager.rb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index c4338f348..99b1379bc 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -1,3 +1,5 @@ +require 'pry' + require_relative 'room' module Hotel @@ -5,8 +7,8 @@ class BookingManager attr_accessor :rooms, :reservations def initialize - @rooms = populate_room_list - @reservations = reservations + @rooms = populate_room_list(20) + @reservations = make_reservation_list # Does a room necessarily have reservations? end # of def initialize # Create list of rooms as list of room Instances @@ -19,15 +21,28 @@ def populate_room_list(number_rooms) rooms << room num += 1 end # of number_rooms loop - end # of populate_room_list method + return rooms + end # of populate_room_list method + + # Create array to store all of reservations + def make_reservation_list + reservations = [] + return reservations + end + + # Method to list all reservations + def list_reservations + return @reservations + end # Method to list all rooms in hotel # def list_rooms # @rooms # end - # Method to list all reservations - # def list_reservations + # Method to add a reservation to list of reservations + # def add_reservation(reservation) + # # end # Method to get total cost of reservation From 0e405f9af37a5f62e997d02106729a0480e274e2 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 17:04:24 -0700 Subject: [PATCH 18/87] Deleted require relative to booking_manager in room.rb since booking_manager already requires room --- lib/room.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index 1fb175c34..720090a16 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,20 +1,18 @@ -require_relative 'booking_manager' +# require_relative 'booking_manager' module Hotel class Room attr_reader :number - attr_accessor :availability def initialize(number) - @number = number.to_i - @availability = check_availability + @number = number # should this be a string ? end def check_availability(start_date, end_date) # Do..something with dates. # if date of check is within range # return boolean - availability = true + availability = true return availability end # of check_availability From e090bb6ba349e8b244212110b82581fbc2ed447b Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 17:06:17 -0700 Subject: [PATCH 19/87] Deleted extra line spaces in booking_manager_spec.rb --- spec/booking_manager_spec.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index ee24e9618..a3ffd232a 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -7,7 +7,7 @@ expect(manager).must_be_kind_of Hotel::BookingManager end # of it instance bookingmanager - it "creates the proper structures for instance variables instantiated" do + it "creates the proper structures for instance variables instantiated" do hotel_rooms = Hotel::BookingManager.new expect (hotel_rooms.rooms).must_be_kind_of Array @@ -15,7 +15,4 @@ end end # of initializer describe - - - end # end of describe BookingManager class From cfba273b47d07ca0d6761a1942e7ec1b5a756ad3 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 21:14:51 -0700 Subject: [PATCH 20/87] Deleted hard coding of 20 rooms in constructor and replaced with parameterto pass in --- lib/booking_manager.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 99b1379bc..7cb32a84d 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -1,4 +1,4 @@ -require 'pry' +# require 'pry' require_relative 'room' @@ -6,9 +6,9 @@ module Hotel class BookingManager attr_accessor :rooms, :reservations - def initialize - @rooms = populate_room_list(20) - @reservations = make_reservation_list # Does a room necessarily have reservations? + def initialize(number_rooms) + @rooms = populate_room_list(number_rooms) #(20) + @reservations = make_reservation_list end # of def initialize # Create list of rooms as list of room Instances @@ -18,9 +18,11 @@ def populate_room_list(number_rooms) number_rooms.times do |room| room = Room.new(num) + # room = "Room \# #{num}" rooms << room num += 1 end # of number_rooms loop + return rooms end # of populate_room_list method From c9a97ae8b5ba202035520eea1e1653e4a3529b69 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 21:17:21 -0700 Subject: [PATCH 21/87] Added paramter to previous calls of BookingManager.new. Added tests for Populate Room List method --- spec/booking_manager_spec.rb | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index a3ffd232a..80cf37f07 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -2,17 +2,39 @@ describe "BookingManager class" do describe "Initializer" do - it "is an instance of BookingManager" do - manager = Hotel::BookingManager.new + it "creates an instance of BookingManager" do + manager = Hotel::BookingManager.new(10) expect(manager).must_be_kind_of Hotel::BookingManager end # of it instance bookingmanager it "creates the proper structures for instance variables instantiated" do - hotel_rooms = Hotel::BookingManager.new + hotel_rooms = Hotel::BookingManager.new(20) - expect (hotel_rooms.rooms).must_be_kind_of Array - expect (hotel_rooms.reservations).must_be_kind_of Array + expect(hotel_rooms.rooms).must_be_kind_of Array + expect(hotel_rooms.reservations).must_be_kind_of Array + # expect hotel_rooms.rooms.length must_equal 20 end end # of initializer describe + describe "Populate Room List method" do + it "creates an array of Room instances" do + hotel_rooms = Hotel::BookingManager.new(10) + first_room = hotel_rooms.rooms.first + last_room = hotel_rooms.rooms.last + + expect(first_room).must_be_instance_of Hotel::Room + expect(last_room).must_be_instance_of Hotel::Room + end # of array Room instance it + + it "assigns numbers to rooms consecutively as instantiated" do + x = 15 + hotel_rooms = Hotel::BookingManager.new(x) + first_room = hotel_rooms.rooms.first + last_room = hotel_rooms.rooms.last + + expect(first_room.number).must_equal 1 + expect(last_room.number).must_equal x + end + end # of reservation and room load methods + end # end of describe BookingManager class From 8891e1ad8d51c7bb1d46fe26f5cfc1dc7c940747 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 4 Sep 2018 21:28:00 -0700 Subject: [PATCH 22/87] Added test to booking_manager_spec to check that number of rooms is equal to constructor parameter passed in --- spec/booking_manager_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 80cf37f07..422809a4d 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -35,6 +35,12 @@ expect(first_room.number).must_equal 1 expect(last_room.number).must_equal x end + + it "returns array of rooms with length equal to parameter passed into constructor" do + x = 12 + hotel_rooms = Hotel::BookingManager.new(x) + expect(hotel_rooms.rooms.length).must_equal x + end end # of reservation and room load methods end # end of describe BookingManager class From 281659cb5d9178f4faf7c11598a0f7d98de1fcd3 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 11:58:49 -0700 Subject: [PATCH 23/87] Added tests for reservation list creator method to booking_manager_spec.rb --- spec/booking_manager_spec.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 422809a4d..1e520f717 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -41,6 +41,18 @@ hotel_rooms = Hotel::BookingManager.new(x) expect(hotel_rooms.rooms.length).must_equal x end - end # of reservation and room load methods + end # of room load methods + + describe "Reservation List creator method" do + it "returns a value equal to @reservations at instantiation" do + hotel_rooms = Hotel::BookingManager.new(10) + expect(hotel_rooms.reservations).must_equal hotel_rooms.make_reservation_list + end + + it "returns an empty array as the list of reservations" do + hotel_rooms = Hotel::BookingManager.new(5) + expect(hotel_rooms.make_reservation_list).must_be_empty + end + end # of reservation list test do end # end of describe BookingManager class From af5e592b6e30f993b7b019099134927a94e9c175 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 12:24:02 -0700 Subject: [PATCH 24/87] Changed assertions in Populate Room List tests to explicitly call BookingManager#populate_room_list --- spec/booking_manager_spec.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 1e520f717..41d9ab65e 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -18,19 +18,25 @@ describe "Populate Room List method" do it "creates an array of Room instances" do - hotel_rooms = Hotel::BookingManager.new(10) - first_room = hotel_rooms.rooms.first - last_room = hotel_rooms.rooms.last + # hotel_rooms = Hotel::BookingManager.new(10) + # first_room = hotel_rooms.rooms.first + # last_room = hotel_rooms.rooms.last + # + # expect(first_room).must_be_instance_of Hotel::Room + # expect(last_room).must_be_instance_of Hotel::Room - expect(first_room).must_be_instance_of Hotel::Room - expect(last_room).must_be_instance_of Hotel::Room + ## Changed to assertions that explicitly call method + new_rooms = Hotel::BookingManager.new(10) + expect(new_rooms.populate_room_list(10)).must_be_kind_of Array + expect(new_rooms.populate_room_list(10).first).must_be_instance_of Hotel::Room + expect(new_rooms.populate_room_list(10).last).must_be_instance_of Hotel::Room end # of array Room instance it it "assigns numbers to rooms consecutively as instantiated" do x = 15 hotel_rooms = Hotel::BookingManager.new(x) - first_room = hotel_rooms.rooms.first - last_room = hotel_rooms.rooms.last + first_room = hotel_rooms.populate_room_list(x).first + last_room = hotel_rooms.populate_room_list(x).last expect(first_room.number).must_equal 1 expect(last_room.number).must_equal x From fbfaa8ed62a0771e1cb03ee9b9c8a71edb202dcf Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 13:48:02 -0700 Subject: [PATCH 25/87] Uncommented BookingManager#list_reservations --- lib/booking_manager.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 7cb32a84d..1aa9afa3f 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -1,5 +1,4 @@ # require 'pry' - require_relative 'room' module Hotel @@ -36,15 +35,15 @@ def make_reservation_list def list_reservations return @reservations end - +# binding.pry # Method to list all rooms in hotel - # def list_rooms - # @rooms - # end + def list_rooms + @rooms + end # Method to add a reservation to list of reservations # def add_reservation(reservation) - # + # @reservations << reservation # end # Method to get total cost of reservation From 45df5ed3676d59d20daab0e24c8eb6648a33e3e5 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 13:51:02 -0700 Subject: [PATCH 26/87] Added test for list_reservations to booking_manager_spec --- spec/booking_manager_spec.rb | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 41d9ab65e..aeb44aa8f 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -12,20 +12,19 @@ expect(hotel_rooms.rooms).must_be_kind_of Array expect(hotel_rooms.reservations).must_be_kind_of Array - # expect hotel_rooms.rooms.length must_equal 20 end + + # it "assigns instance variables to values returned from class methods" do + # hotel_rooms = Hotel::BookingManager.new(5) + # + # expect(hotel_rooms.rooms).must_equal hotel_rooms.populate_room_list(5) + # expect(hotel_rooms.reservations).must_equal hotel_rooms.make_reservation_list + # end end # of initializer describe - describe "Populate Room List method" do - it "creates an array of Room instances" do - # hotel_rooms = Hotel::BookingManager.new(10) - # first_room = hotel_rooms.rooms.first - # last_room = hotel_rooms.rooms.last - # - # expect(first_room).must_be_instance_of Hotel::Room - # expect(last_room).must_be_instance_of Hotel::Room - ## Changed to assertions that explicitly call method + describe "populate_room_list method" do + it "creates an array of Room instances" do new_rooms = Hotel::BookingManager.new(10) expect(new_rooms.populate_room_list(10)).must_be_kind_of Array expect(new_rooms.populate_room_list(10).first).must_be_instance_of Hotel::Room @@ -45,11 +44,12 @@ it "returns array of rooms with length equal to parameter passed into constructor" do x = 12 hotel_rooms = Hotel::BookingManager.new(x) - expect(hotel_rooms.rooms.length).must_equal x + expect(hotel_rooms.populate_room_list(x).length).must_equal x end end # of room load methods - describe "Reservation List creator method" do + + describe "make_reservation_list method" do it "returns a value equal to @reservations at instantiation" do hotel_rooms = Hotel::BookingManager.new(10) expect(hotel_rooms.reservations).must_equal hotel_rooms.make_reservation_list @@ -61,4 +61,11 @@ end end # of reservation list test do + describe "list_reservations method" do + it "returns an array" do + hotel_rooms = Hotel::BookingManager.new(5) + expect(hotel_rooms.list_reservations).must_be_kind_of Array + end + end + end # end of describe BookingManager class From ea97fad26c0d2a99f7bf98b551df63a8ea32d838 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 13:51:44 -0700 Subject: [PATCH 27/87] Deleted new line in room_spec --- spec/room_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/room_spec.rb b/spec/room_spec.rb index e4d78ed3c..d07365568 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -1,7 +1,6 @@ require_relative 'spec_helper' describe "Room class" do - describe "Initializer" do it "is an instance of Room" do number = 2 From 65d9326eb3e0e38341d120bacd0e4a2ca1706881 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 13:58:31 -0700 Subject: [PATCH 28/87] Added test for BookingManager#list_rooms to booking_manager_spec --- spec/booking_manager_spec.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index aeb44aa8f..11571a84d 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -63,9 +63,16 @@ describe "list_reservations method" do it "returns an array" do - hotel_rooms = Hotel::BookingManager.new(5) + hotel_rooms = Hotel::BookingManager.new(7) expect(hotel_rooms.list_reservations).must_be_kind_of Array end end + describe "list_rooms method" do + it "returns an array" do + hotel_rooms = Hotel::BookingManager.new(5) + expect(hotel_rooms.list_rooms).must_be_kind_of Array + end + end + end # end of describe BookingManager class From 50a7a423a0bf7e549d5f43191f42622347199383 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 14:14:31 -0700 Subject: [PATCH 29/87] Added test to check BookingManager#list_rooms number of rooms in booking_manager_spec --- spec/booking_manager_spec.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 11571a84d..541600524 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -69,9 +69,16 @@ end describe "list_rooms method" do - it "returns an array" do + it "returns an array of Room instances" do hotel_rooms = Hotel::BookingManager.new(5) expect(hotel_rooms.list_rooms).must_be_kind_of Array + expect(hotel_rooms.list_rooms.first).must_be_instance_of Hotel::Room + end + + it "returns an array with the given number of rooms" do + x = 5 + hotel_rooms = Hotel::BookingManager.new(x) + expect(hotel_rooms.list_rooms.length).must_equal x end end From 58fa8040af0f1c40d3060e7b006ea97a8beacb29 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 14:18:13 -0700 Subject: [PATCH 30/87] Commented out Room#check_availability --- lib/room.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index 720090a16..bd5406138 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -8,13 +8,13 @@ def initialize(number) @number = number # should this be a string ? end - def check_availability(start_date, end_date) - # Do..something with dates. - # if date of check is within range - # return boolean - availability = true - return availability - end # of check_availability + # def check_availability(start_date, end_date) + # # Do..something with dates. + # # if date of check is within range + # # return boolean + # availability = true + # return availability + # end # of check_availability end # of class Room end # of module Hotel From 65c90623f18696ecf907cb18e14348f60dce9ff5 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 14:39:58 -0700 Subject: [PATCH 31/87] Uncommented BookingManager#add_reservation --- lib/booking_manager.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 1aa9afa3f..6d1edf385 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -41,12 +41,19 @@ def list_rooms @rooms end - # Method to add a reservation to list of reservations - # def add_reservation(reservation) - # @reservations << reservation - # end + # Method to add a reservation to list of reservations + def add_reservation(reservation) + @reservations << reservation + end # Method to get total cost of reservation + # Method to check room availability here? Or in room? + # when check if something is available + # search through reservations for room with nil -> reserve + # if none with nil, search from beginning for date with specific dates. + # if found, move to next room to check. + # do rooms have a list of reserved dates? or no knowledge of dates? + end # of class BookingManager end # of module Hotel From 285d6767bc6a858cdedfa152bbbe4000946e483a Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 14:41:05 -0700 Subject: [PATCH 32/87] Added test for BookingManager#add_reservation in booking_manager_spec --- spec/booking_manager_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 541600524..1e14a20e1 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -82,4 +82,23 @@ end end + describe "add_reservation method" do + before do + @hotel_rooms = Hotel::BookingManager.new(5) + end + + it "increases the length of the reservations array by one" do + old_number = @hotel_rooms.reservations.length + new_booking = "new reservation" + + @hotel_rooms.add_reservation(new_booking) + expect(@hotel_rooms.reservations.length).must_equal old_number + 1 + end + + # it "adds an instance of Reservation to array of reservations" do + # + # end + end + + end # end of describe BookingManager class From 89b9670f4b1951c67a9929a3e7fb729cd1d943ae Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 14:54:32 -0700 Subject: [PATCH 33/87] Created reservation class file and reservation_spec --- lib/reservation.rb | 0 spec/reservation_spec.rb | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/reservation.rb create mode 100644 spec/reservation_spec.rb diff --git a/lib/reservation.rb b/lib/reservation.rb new file mode 100644 index 000000000..e69de29bb diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb new file mode 100644 index 000000000..e69de29bb From bba8e602b76cbc35a335fe30248d82a89247b189 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 14:58:56 -0700 Subject: [PATCH 34/87] Added require_relative for reservation element to booking_manager and spec_helper files --- lib/booking_manager.rb | 8 +++++++- spec/spec_helper.rb | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 6d1edf385..b99071016 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -1,5 +1,6 @@ # require 'pry' require_relative 'room' +require_relative 'reservation' module Hotel class BookingManager @@ -41,19 +42,24 @@ def list_rooms @rooms end + # Create a new instance of Reservation # should this and add_reservation be one method? + def reserve(room) + end + # Method to add a reservation to list of reservations def add_reservation(reservation) @reservations << reservation end # Method to get total cost of reservation + # Get cost from reservation? # Method to check room availability here? Or in room? # when check if something is available # search through reservations for room with nil -> reserve # if none with nil, search from beginning for date with specific dates. # if found, move to next room to check. - # do rooms have a list of reserved dates? or no knowledge of dates? + # do rooms have a list of reserved dates? or no knowledge of dates? end # of class BookingManager end # of module Hotel diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ba44ea20e..a3d07fd59 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,5 +11,6 @@ # Require_relative your lib files here! require_relative '../lib/room.rb' require_relative '../lib/booking_manager.rb' +require_relative '../lib/reservation.rb' # require_relative '..' From e2cd78471eb7b783035c68de4cab1fb2400df141 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 15:38:17 -0700 Subject: [PATCH 35/87] Created class Reservation with attr and initialize method --- lib/reservation.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/reservation.rb b/lib/reservation.rb index e69de29bb..289177a8f 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -0,0 +1,15 @@ +module Hotel + class Reservation + attr_reader :room + attr_accessor :guest_name, :start_date, :end_date, :cost_per_night + + def initialize(room, guest_name:, start_date:, end_date:, cost_per_night: 200.00) + @room_number = room.number + @guest_name = guest_name + @start_date = start_date + @end_date = end_date + @cost_per_night = cost_per_night + end # of initialize method + + end# of class Reservation +end #of Hotel module From 84f7cfb8835e3ffe7322e50b0519ec8e8342ea5a Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 15:39:07 -0700 Subject: [PATCH 36/87] Deleted commented out require_relative --- lib/room.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index bd5406138..1a962b5c5 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,5 +1,3 @@ -# require_relative 'booking_manager' - module Hotel class Room attr_reader :number From 45316b4f026c9a90f7487bb2490ad7fbef524f72 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Wed, 5 Sep 2018 16:33:06 -0700 Subject: [PATCH 37/87] Added test to reservation_spec to check that method creates instance of Reservation --- spec/reservation_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb index e69de29bb..04c90e60d 100644 --- a/spec/reservation_spec.rb +++ b/spec/reservation_spec.rb @@ -0,0 +1,19 @@ +require_relative 'spec_helper' + +describe "Reservation class" do + describe "initialize method" do + before do + @manager = Hotel::BookingManager.new(1) + @room = @manager.rooms.first + @new_booking = Hotel::Reservation.new(@room, guest_name: "Tina Fey", start_date: "June 4", end_date: "June 7") + end + + it "creates a new instance of Reservation" do + expect(@new_booking).must_be_instance_of Hotel::Reservation + end # of new reservation is new instance it + + end # of initialize method + + + +end # of class Reservation From 4efbbc52b726f2fdf0f7ef70accddc0f5d0d4383 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Thu, 6 Sep 2018 14:08:02 -0700 Subject: [PATCH 38/87] Edited date instance variables in class Reservation to Date.parse input --- lib/reservation.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 289177a8f..b98d43268 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -4,10 +4,10 @@ class Reservation attr_accessor :guest_name, :start_date, :end_date, :cost_per_night def initialize(room, guest_name:, start_date:, end_date:, cost_per_night: 200.00) - @room_number = room.number + @room = room.number @guest_name = guest_name - @start_date = start_date - @end_date = end_date + @start_date = Date.parse(start_date) + @end_date = Date.parse(end_date) @cost_per_night = cost_per_night end # of initialize method From 2713f1a7a37b656dbfdad7e0b9dc68168efbe6ed Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Thu, 6 Sep 2018 15:00:20 -0700 Subject: [PATCH 39/87] Edited spacing --- lib/booking_manager.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index b99071016..33a0dcf54 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -36,7 +36,8 @@ def make_reservation_list def list_reservations return @reservations end -# binding.pry + # binding.pry + # Method to list all rooms in hotel def list_rooms @rooms From 9a5953950a68fdd91f3e643e441e4b506430cada Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Thu, 6 Sep 2018 15:04:04 -0700 Subject: [PATCH 40/87] Added test to check that BookingManager#add_reservation adds Reservation instance to reservations instance variable --- spec/booking_manager_spec.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 1e14a20e1..79d4de1c8 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -95,9 +95,14 @@ expect(@hotel_rooms.reservations.length).must_equal old_number + 1 end - # it "adds an instance of Reservation to array of reservations" do - # - # end + it "adds new instance of Reservation to reservations array" do + room = Hotel::Room.new(1) + another_booking = Hotel::Reservation.new(room, guest_name: "Polly Pocket", start_date: "May 10, 2018", end_date: "May 12, 2018") + @hotel_rooms.add_reservation(another_booking) + + expect(@hotel_rooms.reservations.last).must_be_instance_of Hotel::Reservation + expect(@hotel_rooms.reservations.last.guest_name).must_equal "Polly Pocket" + end end From bf1b240ec3b13cdf3f9b6a74f68210c6efa2913c Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Thu, 6 Sep 2018 15:38:27 -0700 Subject: [PATCH 41/87] Edited dates in Reservation initialization test --- spec/reservation_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb index 04c90e60d..527e40a49 100644 --- a/spec/reservation_spec.rb +++ b/spec/reservation_spec.rb @@ -5,13 +5,12 @@ before do @manager = Hotel::BookingManager.new(1) @room = @manager.rooms.first - @new_booking = Hotel::Reservation.new(@room, guest_name: "Tina Fey", start_date: "June 4", end_date: "June 7") + @new_booking = Hotel::Reservation.new(@room, guest_name: "Tina Fey", start_date: "June 11, 2018", end_date: "June 14, 2018") end it "creates a new instance of Reservation" do expect(@new_booking).must_be_instance_of Hotel::Reservation end # of new reservation is new instance it - end # of initialize method From 62a43744ebc8d8b35a02014c13d6b8c2b8ae5d55 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Thu, 6 Sep 2018 16:11:16 -0700 Subject: [PATCH 42/87] Added room_calendar instance variable to initialization and make_room_calendar method --- lib/booking_manager.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 33a0dcf54..a25f733cf 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -9,6 +9,7 @@ class BookingManager def initialize(number_rooms) @rooms = populate_room_list(number_rooms) #(20) @reservations = make_reservation_list + @room_calendar = make_room_calendar(number_rooms) end # of def initialize # Create list of rooms as list of room Instances @@ -37,7 +38,7 @@ def list_reservations return @reservations end # binding.pry - + # Method to list all rooms in hotel def list_rooms @rooms @@ -52,6 +53,10 @@ def add_reservation(reservation) @reservations << reservation end + def make_room_calendar(number) + @room_calendar = {} + end + # Method to get total cost of reservation # Get cost from reservation? @@ -61,6 +66,6 @@ def add_reservation(reservation) # if none with nil, search from beginning for date with specific dates. # if found, move to next room to check. # do rooms have a list of reserved dates? or no knowledge of dates? - end # of class BookingManager + end # of module Hotel From 729f3f80fa9823aae3d7ce300dc7b891254b88ee Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Thu, 6 Sep 2018 16:26:22 -0700 Subject: [PATCH 43/87] Added BookingManager#make_room_calendar to store room reserved dates --- lib/booking_manager.rb | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index a25f733cf..d45eecc91 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -33,6 +33,17 @@ def make_reservation_list return reservations end + # Create list of rooms with reserved dates. Change name? + def make_room_calendar(number) # combine with @rooms? + @room_calendar = {} + + number.times do |num| + dates_reserved = [] + @room_calendar[:num] = dates_reserved + end + return @room_calendar + end + # Method to list all reservations def list_reservations return @reservations @@ -41,22 +52,18 @@ def list_reservations # Method to list all rooms in hotel def list_rooms - @rooms + return @rooms end - # Create a new instance of Reservation # should this and add_reservation be one method? - def reserve(room) - end + # # Create a new instance of Reservation # should this and add_reservation be one method? + # def reserve(room) + # end # Method to add a reservation to list of reservations def add_reservation(reservation) @reservations << reservation end - def make_room_calendar(number) - @room_calendar = {} - end - # Method to get total cost of reservation # Get cost from reservation? From bde02266cfbddfcbbfa01dbd60a4678d1b3f037e Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Thu, 6 Sep 2018 17:50:36 -0700 Subject: [PATCH 44/87] Completed BookingManager#maked_room_calendar and #add_reservation_to_calendar --- lib/booking_manager.rb | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index d45eecc91..9f8de37d4 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -1,6 +1,7 @@ # require 'pry' require_relative 'room' require_relative 'reservation' +# require 'pry' module Hotel class BookingManager @@ -38,10 +39,32 @@ def make_room_calendar(number) # combine with @rooms? @room_calendar = {} number.times do |num| - dates_reserved = [] - @room_calendar[:num] = dates_reserved + dates_reserved = {} #[] + @room_calendar[num+1] = dates_reserved end + + return @room_calendar + end + + # # Create a new instance of Reservation # should this and add_reservation be one method? + # def reserve(room) + # end + + # Method to add a reservation to list of reservations + def add_reservation(reservation) + @reservations << reservation + # @room_calendar + # + # reserved_message = "Room successfully reserved" + # return reserved_message + end + + # Add reservation date to hash of room reserved dates + def add_reservation_to_calendar(reservation) + @room_calendar[reservation.room][reservation.start_date] = reservation + # binding.pry return @room_calendar + end # Method to list all reservations @@ -55,14 +78,7 @@ def list_rooms return @rooms end - # # Create a new instance of Reservation # should this and add_reservation be one method? - # def reserve(room) - # end - # Method to add a reservation to list of reservations - def add_reservation(reservation) - @reservations << reservation - end # Method to get total cost of reservation # Get cost from reservation? From 0025f00b9334a52a890556f42a0ad0c077e40b8c Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Thu, 6 Sep 2018 17:55:31 -0700 Subject: [PATCH 45/87] Fixed test for add_reservation_to_calendar so does not call nonexistent room --- spec/booking_manager_spec.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 79d4de1c8..824c73b95 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -103,7 +103,17 @@ expect(@hotel_rooms.reservations.last).must_be_instance_of Hotel::Reservation expect(@hotel_rooms.reservations.last.guest_name).must_equal "Polly Pocket" end - end + end # of add_reservation method + + describe "add_reservation_to_calendar method" do + it "creates a hash with room number as key and dates as hash" do + hotel = Hotel::BookingManager.new(3) + room = Hotel::Room.new(3) + another_booking = Hotel::Reservation.new(room, guest_name: "Kim Possible", start_date: "June 11, 2018", end_date: "June 14, 2018") + expect(hotel.add_reservation_to_calendar(another_booking)).must_be_kind_of Hash + end # end of add reservation to calendar method hash room key it + + end # of add reservation to calendar method end # end of describe BookingManager class From 82b3c8722b9997261cc94c8364fe2319ef824832 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 11:22:45 -0700 Subject: [PATCH 46/87] Added room calendar to attr_accessor and pseudocode for add_reservation_to_calendar loop for whole date range --- lib/booking_manager.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 9f8de37d4..e0129e32a 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -1,11 +1,10 @@ -# require 'pry' require_relative 'room' require_relative 'reservation' # require 'pry' module Hotel class BookingManager - attr_accessor :rooms, :reservations + attr_accessor :rooms, :reservations, :room_calendar def initialize(number_rooms) @rooms = populate_room_list(number_rooms) #(20) @@ -42,7 +41,7 @@ def make_room_calendar(number) # combine with @rooms? dates_reserved = {} #[] @room_calendar[num+1] = dates_reserved end - + # binding.pry return @room_calendar end @@ -61,12 +60,27 @@ def add_reservation(reservation) # Add reservation date to hash of room reserved dates def add_reservation_to_calendar(reservation) - @room_calendar[reservation.room][reservation.start_date] = reservation + # until reservation start date = reservation end date -1 + # add to calendar. What changes is date. + @room_calendar[reservation.room][reservation.start_date] = reservation # dependency on instance variables # binding.pry return @room_calendar end + # {1=>{}, + # 2=>{}, + # 3=> + # {#=> + # #, + # @guest_name="Kim Possible", + # @room=3, + # @start_date= + # #>}} + # Method to list all reservations def list_reservations return @reservations From f9862e91783e0ad087220182579f66a5fe0a3ad5 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 11:24:28 -0700 Subject: [PATCH 47/87] Added assertion to add_reservation_to_calendar test to check that date was added to room_calendar hash --- spec/booking_manager_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 824c73b95..b5a1adbc8 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -112,6 +112,7 @@ room = Hotel::Room.new(3) another_booking = Hotel::Reservation.new(room, guest_name: "Kim Possible", start_date: "June 11, 2018", end_date: "June 14, 2018") expect(hotel.add_reservation_to_calendar(another_booking)).must_be_kind_of Hash + expect(hotel.room_calendar[3]).must_include Date.parse("June 11, 2018") end # end of add reservation to calendar method hash room key it end # of add reservation to calendar method From 565cfea2367dac566ba90db7b0de9fe6079bb989 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 11:53:29 -0700 Subject: [PATCH 48/87] Added code to BookingManager#add_reservation_to_calendar to add each night to room_calendar hash instead of just start date --- lib/booking_manager.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index e0129e32a..f23523124 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -62,10 +62,14 @@ def add_reservation(reservation) def add_reservation_to_calendar(reservation) # until reservation start date = reservation end date -1 # add to calendar. What changes is date. - @room_calendar[reservation.room][reservation.start_date] = reservation # dependency on instance variables + date = reservation.start_date + + reservation.number_nights.to_i.times do + @room_calendar[reservation.room][date] = reservation # dependency on instance variables + date += 1 + end # binding.pry return @room_calendar - end # {1=>{}, From aa20313173476186d2b2bbb4626cb9cd0f0ad6be Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 11:56:20 -0700 Subject: [PATCH 49/87] Added @number_nights to constructor of class Reservation --- lib/reservation.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index b98d43268..98e64bd31 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,6 +1,6 @@ module Hotel class Reservation - attr_reader :room + attr_reader :room, :number_nights attr_accessor :guest_name, :start_date, :end_date, :cost_per_night def initialize(room, guest_name:, start_date:, end_date:, cost_per_night: 200.00) @@ -9,6 +9,7 @@ def initialize(room, guest_name:, start_date:, end_date:, cost_per_night: 200.00 @start_date = Date.parse(start_date) @end_date = Date.parse(end_date) @cost_per_night = cost_per_night + @number_nights = @end_date - @start_date end # of initialize method end# of class Reservation From eb917593873b45a0cc3fd587dc817bc4c7ecf2a5 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 12:02:34 -0700 Subject: [PATCH 50/87] Moved Reservation.number_nights conversion to integer from BookingManager to Reservation constructor --- lib/booking_manager.rb | 8 +++----- lib/reservation.rb | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index f23523124..9863eb2e3 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -58,14 +58,12 @@ def add_reservation(reservation) # return reserved_message end - # Add reservation date to hash of room reserved dates + # Add reservation date range to hash of room reserved dates def add_reservation_to_calendar(reservation) - # until reservation start date = reservation end date -1 - # add to calendar. What changes is date. date = reservation.start_date - reservation.number_nights.to_i.times do - @room_calendar[reservation.room][date] = reservation # dependency on instance variables + reservation.number_nights.times do + @room_calendar[reservation.room][date] = reservation # dependency date += 1 end # binding.pry diff --git a/lib/reservation.rb b/lib/reservation.rb index 98e64bd31..a189f8ccc 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -9,7 +9,7 @@ def initialize(room, guest_name:, start_date:, end_date:, cost_per_night: 200.00 @start_date = Date.parse(start_date) @end_date = Date.parse(end_date) @cost_per_night = cost_per_night - @number_nights = @end_date - @start_date + @number_nights = (@end_date - @start_date).to_i end # of initialize method end# of class Reservation From 5fb51ec87ad03cf4e67e0c42daf2f4cbb3986d26 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 12:24:19 -0700 Subject: [PATCH 51/87] Added BookingManager#get_reservation_cost --- lib/booking_manager.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 9863eb2e3..5467dcbb5 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -63,7 +63,7 @@ def add_reservation_to_calendar(reservation) date = reservation.start_date reservation.number_nights.times do - @room_calendar[reservation.room][date] = reservation # dependency + @room_calendar[reservation.room][date] = reservation # dependency date += 1 end # binding.pry @@ -94,12 +94,13 @@ def list_rooms return @rooms end - - # Method to get total cost of reservation - # Get cost from reservation? + def get_reservation_cost(nights, cost_per_night) + total_cost = nights * cost_per_night + return total_cost + end - # Method to check room availability here? Or in room? + # Method to check room availability here? Or in room? Or calendar? # when check if something is available # search through reservations for room with nil -> reserve # if none with nil, search from beginning for date with specific dates. From b34e6f06acfd365ca8dc5d3413acb6bd31385c65 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 12:39:21 -0700 Subject: [PATCH 52/87] Added test for BookingManager#get_reservation_cost --- spec/booking_manager_spec.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index b5a1adbc8..b0ee0bd3e 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -114,7 +114,16 @@ expect(hotel.add_reservation_to_calendar(another_booking)).must_be_kind_of Hash expect(hotel.room_calendar[3]).must_include Date.parse("June 11, 2018") end # end of add reservation to calendar method hash room key it - end # of add reservation to calendar method + describe "get_reservation_cost method" do + it "returns the total cost of the reservation" do + hotel = Hotel::BookingManager.new(3) + room = Hotel::Room.new(3) + booking = Hotel::Reservation.new(room, guest_name: "Tony Tonson", start_date: "June 10, 2018", end_date: "June 12, 2018") + + expect(hotel.get_reservation_cost(booking.cost_per_night, booking.number_nights)).must_be_close_to 400 + end # returns product it + end # of get_reservation_cost method" + end # end of describe BookingManager class From c962098f33a4964a10e05678832e236207c4b3bc Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 15:13:26 -0700 Subject: [PATCH 53/87] Added test for invalid date Argument Error in Reservation --- spec/reservation_spec.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb index 527e40a49..75a94f04a 100644 --- a/spec/reservation_spec.rb +++ b/spec/reservation_spec.rb @@ -5,12 +5,17 @@ before do @manager = Hotel::BookingManager.new(1) @room = @manager.rooms.first - @new_booking = Hotel::Reservation.new(@room, guest_name: "Tina Fey", start_date: "June 11, 2018", end_date: "June 14, 2018") end it "creates a new instance of Reservation" do - expect(@new_booking).must_be_instance_of Hotel::Reservation + new_booking = Hotel::Reservation.new(@room, guest_name: "Tina Fey", start_date: "June 11, 2018", end_date: "June 14, 2018") + expect(new_booking).must_be_instance_of Hotel::Reservation end # of new reservation is new instance it + + it "raises an ArgumentError for an invalid date range" do + new_booking = Hotel::Reservation.new(@room, guest_name: "Tina Fey", start_date: "June 11, 2018", end_date: "June 10, 2018") + expect(new_booking).must_raise ArgumentError + end # of invalid date range ArgumentError end # of initialize method From 9369c7706b677126c7333a4fbaf6d710c281d680 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 16:35:34 -0700 Subject: [PATCH 54/87] Added Reservation#check_dates method --- lib/reservation.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index a189f8ccc..e7b27625c 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -6,11 +6,18 @@ class Reservation def initialize(room, guest_name:, start_date:, end_date:, cost_per_night: 200.00) @room = room.number @guest_name = guest_name + check_dates(start_date, end_date) @start_date = Date.parse(start_date) @end_date = Date.parse(end_date) @cost_per_night = cost_per_night - @number_nights = (@end_date - @start_date).to_i + @number_nights = (@end_date - @start_date).to_i end # of initialize method + def check_dates(start_date, end_date) + if start_date > end_date + raise ArgumentError.new "Invalid date range. Start date must be before end date." + end + end + end# of class Reservation end #of Hotel module From aac994ec417b09fffce20bff78ba6b6b782290a3 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 16:39:12 -0700 Subject: [PATCH 55/87] Fixed invalid date range test for Reservation constructor --- spec/reservation_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb index 75a94f04a..5ed4d3d3e 100644 --- a/spec/reservation_spec.rb +++ b/spec/reservation_spec.rb @@ -3,7 +3,7 @@ describe "Reservation class" do describe "initialize method" do before do - @manager = Hotel::BookingManager.new(1) + @manager = Hotel::BookingManager.new(5) @room = @manager.rooms.first end @@ -13,8 +13,10 @@ end # of new reservation is new instance it it "raises an ArgumentError for an invalid date range" do - new_booking = Hotel::Reservation.new(@room, guest_name: "Tina Fey", start_date: "June 11, 2018", end_date: "June 10, 2018") - expect(new_booking).must_raise ArgumentError + proc { + booking = Hotel::Reservation.new(@room, guest_name: "Tina Fey", start_date: "June 11, 2018", end_date: "June 10, 2018") + }.must_raise ArgumentError + #proc {booking.check_dates(booking.start_date, booking.end_date)}.must_raise ArgumentError end # of invalid date range ArgumentError end # of initialize method From 5edf06e8aeb38382aeb6b700d18279a70a1224d0 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 20:57:46 -0700 Subject: [PATCH 56/87] Added test for find_reservations_on_date to booking_manager_spec --- spec/booking_manager_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index b0ee0bd3e..722bf614a 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -113,6 +113,7 @@ another_booking = Hotel::Reservation.new(room, guest_name: "Kim Possible", start_date: "June 11, 2018", end_date: "June 14, 2018") expect(hotel.add_reservation_to_calendar(another_booking)).must_be_kind_of Hash expect(hotel.room_calendar[3]).must_include Date.parse("June 11, 2018") + expect(hotel.room_calendar[3].length).must_equal another_booking.number_nights end # end of add reservation to calendar method hash room key it end # of add reservation to calendar method @@ -126,4 +127,18 @@ end # returns product it end # of get_reservation_cost method" + describe "find_reservations_on_date method" do + it "returns all reservations on the desired date" do + hotel = Hotel::BookingManager.new(5) + room1 = Hotel::Room.new(1) + room3 = Hotel::Room.new(2) + booking1 = Hotel::Reservation.new(room1, guest_name: "Tony Blaze", start_date: "June 10, 2018", end_date: "June 12, 2018") + booking2 = Hotel::Reservation.new(room3, guest_name: "Jessie Jade", start_date: "June 10, 2018", end_date: "June 14, 2018") + hotel.add_reservation_to_calendar(booking1) + hotel.add_reservation_to_calendar(booking2) + + expect(hotel.find_reservations_on_date("June 11, 2018", hotel.room_calendar).length).must_equal 2 + end # of returns all reservations on date it + end # of find_reservations_on_date method + end # end of describe BookingManager class From 8c6d95fe047bf0ec1c35de10ef31cd79e37e16a9 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 21:00:48 -0700 Subject: [PATCH 57/87] Added BookingManager#find_reservations_on_date --- lib/booking_manager.rb | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 5467dcbb5..6915efad8 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -94,6 +94,12 @@ def list_rooms return @rooms end + # Method to return all of reservations for given date + # take in date as parameter + # search through room_calendar to see if any rooms include it as value + # if date is there, add that reservation to an array of days_reseravtions + # return array + # Method to get total cost of reservation def get_reservation_cost(nights, cost_per_night) total_cost = nights * cost_per_night @@ -103,9 +109,23 @@ def get_reservation_cost(nights, cost_per_night) # Method to check room availability here? Or in room? Or calendar? # when check if something is available # search through reservations for room with nil -> reserve - # if none with nil, search from beginning for date with specific dates. - # if found, move to next room to check. - # do rooms have a list of reserved dates? or no knowledge of dates? + def find_reservations_on_date(date, calendar) + search_date = Date.parse(date) + found_reservations = [] + + calendar.each do |room, info| + info.each do |date, reservation| + if date == search_date + found_reservations << reservation + else + next + end + end # of info each + end # end of calendar each + # Add return message for no reservations found? + return found_reservations + end # of find reservation by date method + end # of class BookingManager end # of module Hotel From 4b7d2eb4f7993454391baba64d2a6f2c70d09921 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Fri, 7 Sep 2018 21:14:43 -0700 Subject: [PATCH 58/87] Added booking to find_reservations_on_date test to check list is exclusive to only parameter date --- lib/reservation.rb | 2 +- spec/booking_manager_spec.rb | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index e7b27625c..0a8e041b8 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -10,7 +10,7 @@ def initialize(room, guest_name:, start_date:, end_date:, cost_per_night: 200.00 @start_date = Date.parse(start_date) @end_date = Date.parse(end_date) @cost_per_night = cost_per_night - @number_nights = (@end_date - @start_date).to_i + @number_nights = (@end_date - @start_date).to_i end # of initialize method def check_dates(start_date, end_date) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 722bf614a..a105a043c 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -131,11 +131,14 @@ it "returns all reservations on the desired date" do hotel = Hotel::BookingManager.new(5) room1 = Hotel::Room.new(1) - room3 = Hotel::Room.new(2) + room2 = Hotel::Room.new(2) + room3 = Hotel::Room.new(3) booking1 = Hotel::Reservation.new(room1, guest_name: "Tony Blaze", start_date: "June 10, 2018", end_date: "June 12, 2018") - booking2 = Hotel::Reservation.new(room3, guest_name: "Jessie Jade", start_date: "June 10, 2018", end_date: "June 14, 2018") + booking2 = Hotel::Reservation.new(room2, guest_name: "Jessie Jade", start_date: "June 10, 2018", end_date: "June 14, 2018") + booking3 = Hotel::Reservation.new(room3, guest_name: "Jessie Jade", start_date: "June 14, 2018", end_date: "June 16, 2018") hotel.add_reservation_to_calendar(booking1) hotel.add_reservation_to_calendar(booking2) + hotel.add_reservation_to_calendar(booking3) expect(hotel.find_reservations_on_date("June 11, 2018", hotel.room_calendar).length).must_equal 2 end # of returns all reservations on date it From fe06dda2a896c7bcd526dfed6eb417b51b6e5e09 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Sun, 9 Sep 2018 10:00:08 -0700 Subject: [PATCH 59/87] Add test for BookingManager#find_vancancies_on_date to booking_manager_spec --- spec/booking_manager_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index a105a043c..6925ba88f 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -144,4 +144,25 @@ end # of returns all reservations on date it end # of find_reservations_on_date method + describe "find_vacancies_on_date method" do + before do + @hotel = Hotel::BookingManager.new(5) + room1 = Hotel::Room.new(1) + room2 = Hotel::Room.new(2) + room3 = Hotel::Room.new(3) + booking1 = Hotel::Reservation.new(room1, guest_name: "Tony Blaze", start_date: "June 10, 2018", end_date: "June 12, 2018") + booking2 = Hotel::Reservation.new(room2, guest_name: "Jane James", start_date: "June 10, 2018", end_date: "June 14, 2018") + booking3 = Hotel::Reservation.new(room3, guest_name: "Jessie Jade", start_date: "June 14, 2018", end_date: "June 16, 2018") + @hotel.add_reservation_to_calendar(booking1) + @hotel.add_reservation_to_calendar(booking2) + @hotel.add_reservation_to_calendar(booking3) + end + + it "returns array of rooms without reservations on given date" do + expect(@hotel.find_vacancies_on_date("June 10, 2018", @hotel.room_calendar).length).must_equal 3 + expect(@hotel.find_vacancies_on_date("June 17, 2018", @hotel.room_calendar).length).must_equal 5 + end # of find vacancies it + + end # of find vacancies on date method + end # end of describe BookingManager class From 1aa1985d797bd4a487caf3c24c1453d0c2e37989 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Sun, 9 Sep 2018 10:02:11 -0700 Subject: [PATCH 60/87] Add BookingManager#find_vacancies_on_date. Delete find_reservations_on_date pseudocode --- lib/booking_manager.rb | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 6915efad8..86781902a 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -70,20 +70,7 @@ def add_reservation_to_calendar(reservation) return @room_calendar end - # {1=>{}, - # 2=>{}, - # 3=> - # {#=> - # #, - # @guest_name="Kim Possible", - # @room=3, - # @start_date= - # #>}} - - # Method to list all reservations + # Method to list all reservation instances def list_reservations return @reservations end @@ -94,12 +81,6 @@ def list_rooms return @rooms end - # Method to return all of reservations for given date - # take in date as parameter - # search through room_calendar to see if any rooms include it as value - # if date is there, add that reservation to an array of days_reseravtions - # return array - # Method to get total cost of reservation def get_reservation_cost(nights, cost_per_night) total_cost = nights * cost_per_night @@ -116,8 +97,8 @@ def find_reservations_on_date(date, calendar) calendar.each do |room, info| info.each do |date, reservation| if date == search_date - found_reservations << reservation - else + found_reservations << reservation + else next end end # of info each @@ -126,6 +107,21 @@ def find_reservations_on_date(date, calendar) return found_reservations end # of find reservation by date method + def find_vacancies_on_date(date, calendar) + search_date = Date.parse(date) + found_vacancies = [] + + calendar.each do |room, info| + if info == nil + found_vacancies << room + else + info.any? {|date, reservation| date == search_date}? next : found_vacancies << room + end + end + + return found_vacancies + end # of find vacancy + end # of class BookingManager end # of module Hotel From c25a9064cccaa6f518e358b20232e38b8bba12f7 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Sun, 9 Sep 2018 10:29:03 -0700 Subject: [PATCH 61/87] Add assertion to find_vacancies_on_date test for when no vacancies --- spec/booking_manager_spec.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 6925ba88f..8bb5a7247 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -149,10 +149,10 @@ @hotel = Hotel::BookingManager.new(5) room1 = Hotel::Room.new(1) room2 = Hotel::Room.new(2) - room3 = Hotel::Room.new(3) + @room3 = Hotel::Room.new(3) booking1 = Hotel::Reservation.new(room1, guest_name: "Tony Blaze", start_date: "June 10, 2018", end_date: "June 12, 2018") booking2 = Hotel::Reservation.new(room2, guest_name: "Jane James", start_date: "June 10, 2018", end_date: "June 14, 2018") - booking3 = Hotel::Reservation.new(room3, guest_name: "Jessie Jade", start_date: "June 14, 2018", end_date: "June 16, 2018") + booking3 = Hotel::Reservation.new(@room3, guest_name: "Jessie Jade", start_date: "June 14, 2018", end_date: "June 16, 2018") @hotel.add_reservation_to_calendar(booking1) @hotel.add_reservation_to_calendar(booking2) @hotel.add_reservation_to_calendar(booking3) @@ -163,6 +163,20 @@ expect(@hotel.find_vacancies_on_date("June 17, 2018", @hotel.room_calendar).length).must_equal 5 end # of find vacancies it + it "returns message of no vacancies when all rooms are reserved" do + room4 = Hotel::Room.new(4) + room5 = Hotel::Room.new(5) + + booking4 = Hotel::Reservation.new(@room3, guest_name: "Lady Day", start_date: "June 10, 2018", end_date: "June 11, 2018") + booking5 = Hotel::Reservation.new(room4, guest_name: "Horis Who", start_date: "June 8, 2018", end_date: "June 14, 2018") + booking6 = Hotel::Reservation.new(room5, guest_name: "Dorian Damian", start_date: "June 6, 2018", end_date: "June 11, 2018") + + @hotel.add_reservation_to_calendar(booking4) + @hotel.add_reservation_to_calendar(booking5) + @hotel.add_reservation_to_calendar(booking6) + + expect(@hotel.find_vacancies_on_date("June 10, 2018", @hotel.room_calendar).length).must_equal 0 + end # no find_vacancies no vacancy it end # of find vacancies on date method end # end of describe BookingManager class From ad7a1ba6682cb6c6b9882c022fa85bafd0f10d77 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Sun, 9 Sep 2018 10:43:39 -0700 Subject: [PATCH 62/87] Edit invalid date error message in Reservation and dates in tests to reflect date format Month dd, yyyy --- lib/reservation.rb | 2 +- spec/booking_manager_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 0a8e041b8..0e7378ba9 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -15,7 +15,7 @@ def initialize(room, guest_name:, start_date:, end_date:, cost_per_night: 200.00 def check_dates(start_date, end_date) if start_date > end_date - raise ArgumentError.new "Invalid date range. Start date must be before end date." + raise ArgumentError.new "Invalid date range. Start date must be before end date, both in format of 'Month dd, yyyy'. " end end diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 8bb5a7247..01d4707da 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -168,8 +168,8 @@ room5 = Hotel::Room.new(5) booking4 = Hotel::Reservation.new(@room3, guest_name: "Lady Day", start_date: "June 10, 2018", end_date: "June 11, 2018") - booking5 = Hotel::Reservation.new(room4, guest_name: "Horis Who", start_date: "June 8, 2018", end_date: "June 14, 2018") - booking6 = Hotel::Reservation.new(room5, guest_name: "Dorian Damian", start_date: "June 6, 2018", end_date: "June 11, 2018") + booking5 = Hotel::Reservation.new(room4, guest_name: "Horis Who", start_date: "June 08, 2018", end_date: "June 14, 2018") + booking6 = Hotel::Reservation.new(room5, guest_name: "Dorian Damian", start_date: "June 06, 2018", end_date: "June 11, 2018") @hotel.add_reservation_to_calendar(booking4) @hotel.add_reservation_to_calendar(booking5) From e04e5a6b5e0815fecfb240f3fbc0bbc99611e793 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Sun, 9 Sep 2018 10:45:20 -0700 Subject: [PATCH 63/87] Add require date --- spec/spec_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a3d07fd59..717c478a4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ require 'minitest' require 'minitest/autorun' require 'minitest/reporters' +require 'date' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 85ce5655b52e5e9e961780d16526cc63d50c8553 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Sun, 9 Sep 2018 11:00:29 -0700 Subject: [PATCH 64/87] Change return for no vacancies to String message --- lib/booking_manager.rb | 8 ++++++-- spec/booking_manager_spec.rb | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 86781902a..9ba88fa06 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -119,9 +119,13 @@ def find_vacancies_on_date(date, calendar) end end - return found_vacancies + return found_vacancies.empty? ? no_vacancies_message: found_vacancies end # of find vacancy - end # of class BookingManager + def no_vacancies_message + return "There are no vacancies for the given date range." + end + + end # of class BookingManager end # of module Hotel diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 01d4707da..a4d07fade 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -175,7 +175,7 @@ @hotel.add_reservation_to_calendar(booking5) @hotel.add_reservation_to_calendar(booking6) - expect(@hotel.find_vacancies_on_date("June 10, 2018", @hotel.room_calendar).length).must_equal 0 + expect(@hotel.find_vacancies_on_date("June 10, 2018", @hotel.room_calendar)).must_be_kind_of String end # no find_vacancies no vacancy it end # of find vacancies on date method From b08a5b5233bd9be0dfc0d7ee6b509e5e6465d7ee Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Sun, 9 Sep 2018 16:06:58 -0700 Subject: [PATCH 65/87] Add test for reserve_available room and beginning of reserve_available_room method --- lib/booking_manager.rb | 49 ++++++++++++++++++++++++++++++++++-- spec/booking_manager_spec.rb | 27 +++++++++++++++++++- 2 files changed, 73 insertions(+), 3 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 9ba88fa06..d5062a1c3 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -1,6 +1,6 @@ require_relative 'room' require_relative 'reservation' -# require 'pry' +require 'pry' module Hotel class BookingManager @@ -70,6 +70,12 @@ def add_reservation_to_calendar(reservation) return @room_calendar end + def check_dates(start_date, end_date) + if start_date > end_date + raise ArgumentError.new "Invalid date range. Start date must be before end date, both in format of 'Month dd, yyyy'. " + end + end + # Method to list all reservation instances def list_reservations return @reservations @@ -122,10 +128,49 @@ def find_vacancies_on_date(date, calendar) return found_vacancies.empty? ? no_vacancies_message: found_vacancies end # of find vacancy - def no_vacancies_message return "There are no vacancies for the given date range." end + + def reserve_available_room(guest_name, start_date, end_date) + check_dates(start_date, end_date) + room_available = "undefined" + + start_date = Date.parse(start_date) + end_date = Date.parse(end_date) + # should instead use find_vacancies_on_date method? + @room_calendar.each do |room, reserved_dates| + if reserved_dates.empty? + room_available = room + else + search_date = start_date + while search_date < end_date + # search_date.each do |search_date| + if reserved_dates.include? search_date + next + else + room_available = room + exit + #exit? # not next bc shouldn't bother with rest of room + # reserved_dates.each do |reserved_dates + end + search_date += 1 + # end + end + end + # binding.pry + # return room_available + end #@room each + + new_reservation = Reservation.new(room_available, guest_name: guest_name, start_date: start_date, end_date: end_date) + add_reservation(new_reservation) + add_reservation_to_calendar(new_reservation) + binding.pry + return new_reservation + end # def reserve_available_room + + + end # of class BookingManager end # of module Hotel diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index a4d07fade..245532b59 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -175,8 +175,33 @@ @hotel.add_reservation_to_calendar(booking5) @hotel.add_reservation_to_calendar(booking6) - expect(@hotel.find_vacancies_on_date("June 10, 2018", @hotel.room_calendar)).must_be_kind_of String + expect(@hotel.find_vacancies_on_date("June 10, 2018", @hotel.room_calendar)).must_be_kind_of String end # no find_vacancies no vacancy it end # of find vacancies on date method + describe "reserve_available_room method" do + before do + @hotel = Hotel::BookingManager.new(5) + room4 = Hotel::Room.new(4) + room5 = Hotel::Room.new(5) + + booking5 = Hotel::Reservation.new(room4, guest_name: "Horis Who", start_date: "June 08, 2018", end_date: "June 14, 2018") + booking6 = Hotel::Reservation.new(room5, guest_name: "Dorian Damian", start_date: "June 06, 2018", end_date: "June 11, 2018") + + @hotel.add_reservation(booking5) + @hotel.add_reservation(booking6) + # + @number_prior_reservations = @hotel.reservations.length + @hotel.reserve_available_room("Donna Foster", "January 02, 2019", "January 08, 2019") + end + + it "only allows reservations for rooms/dates not already reserved" do + + end + + it "reserves available room for given date range" do + expect(@hotel.reservations.length).must_equal @number_prior_reservations + 1 + end + end # of reserve available room method + end # end of describe BookingManager class From 618275066ee3e2e2e92b236771051936ef5f8366 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Sun, 9 Sep 2018 16:25:28 -0700 Subject: [PATCH 66/87] Edit make_room_calendar to create with instance of Room as key instead of integer --- lib/booking_manager.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index d5062a1c3..6be0ca7b7 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -36,12 +36,18 @@ def make_reservation_list # Create list of rooms with reserved dates. Change name? def make_room_calendar(number) # combine with @rooms? @room_calendar = {} - - number.times do |num| - dates_reserved = {} #[] - @room_calendar[num+1] = dates_reserved + # + # number.times do |num| + # dates_reserved = {} #[] + # @room_calendar[num+1] = dates_reserved + # end + # # binding.pry + # return @room_calendar + @rooms.each do |room| + dates_reserved = {} + @room_calendar[room] = dates_reserved end - # binding.pry + binding.pry return @room_calendar end @@ -166,7 +172,7 @@ def reserve_available_room(guest_name, start_date, end_date) new_reservation = Reservation.new(room_available, guest_name: guest_name, start_date: start_date, end_date: end_date) add_reservation(new_reservation) add_reservation_to_calendar(new_reservation) - binding.pry + # binding.pry return new_reservation end # def reserve_available_room From 263dca11317e7623aba6be6f1951c3564b288ae6 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Mon, 10 Sep 2018 02:12:35 -0700 Subject: [PATCH 67/87] Delete commented comments. Add alternate code for reserve_available_room --- lib/booking_manager.rb | 108 +++++++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 46 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 6be0ca7b7..0fe791b1e 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -1,6 +1,6 @@ require_relative 'room' require_relative 'reservation' -require 'pry' +# require 'pry' module Hotel class BookingManager @@ -10,7 +10,7 @@ def initialize(number_rooms) @rooms = populate_room_list(number_rooms) #(20) @reservations = make_reservation_list @room_calendar = make_room_calendar(number_rooms) - end # of def initialize + end # Create list of rooms as list of room Instances def populate_room_list(number_rooms) @@ -19,13 +19,13 @@ def populate_room_list(number_rooms) number_rooms.times do |room| room = Room.new(num) - # room = "Room \# #{num}" + # rooms << room num += 1 - end # of number_rooms loop + end return rooms - end # of populate_room_list method + end # Create array to store all of reservations def make_reservation_list @@ -41,27 +41,20 @@ def make_room_calendar(number) # combine with @rooms? # dates_reserved = {} #[] # @room_calendar[num+1] = dates_reserved # end - # # binding.pry + # return @room_calendar @rooms.each do |room| dates_reserved = {} @room_calendar[room] = dates_reserved end - binding.pry + return @room_calendar end - # # Create a new instance of Reservation # should this and add_reservation be one method? - # def reserve(room) - # end # Method to add a reservation to list of reservations def add_reservation(reservation) @reservations << reservation - # @room_calendar - # - # reserved_message = "Room successfully reserved" - # return reserved_message end # Add reservation date range to hash of room reserved dates @@ -72,7 +65,7 @@ def add_reservation_to_calendar(reservation) @room_calendar[reservation.room][date] = reservation # dependency date += 1 end - # binding.pry + return @room_calendar end @@ -86,7 +79,7 @@ def check_dates(start_date, end_date) def list_reservations return @reservations end - # binding.pry + # Method to list all rooms in hotel def list_rooms @@ -99,9 +92,6 @@ def get_reservation_cost(nights, cost_per_night) return total_cost end - # Method to check room availability here? Or in room? Or calendar? - # when check if something is available - # search through reservations for room with nil -> reserve def find_reservations_on_date(date, calendar) search_date = Date.parse(date) found_reservations = [] @@ -117,7 +107,7 @@ def find_reservations_on_date(date, calendar) end # end of calendar each # Add return message for no reservations found? return found_reservations - end # of find reservation by date method + end def find_vacancies_on_date(date, calendar) search_date = Date.parse(date) @@ -132,7 +122,7 @@ def find_vacancies_on_date(date, calendar) end return found_vacancies.empty? ? no_vacancies_message: found_vacancies - end # of find vacancy + end def no_vacancies_message return "There are no vacancies for the given date range." @@ -141,42 +131,68 @@ def no_vacancies_message def reserve_available_room(guest_name, start_date, end_date) check_dates(start_date, end_date) - room_available = "undefined" + @room_available = 0 + + res_start_date = Date.parse(start_date) + res_end_date = Date.parse(end_date) - start_date = Date.parse(start_date) - end_date = Date.parse(end_date) - # should instead use find_vacancies_on_date method? @room_calendar.each do |room, reserved_dates| if reserved_dates.empty? - room_available = room - else - search_date = start_date - while search_date < end_date - # search_date.each do |search_date| - if reserved_dates.include? search_date - next - else - room_available = room - exit - #exit? # not next bc shouldn't bother with rest of room - # reserved_dates.each do |reserved_dates - end + @room_available = room + end + + unless reserved_dates.empty? + date_range = [] + search_date = res_start_date + + until search_date > res_end_date + search_date.each do |search_date| + date_range << search_date search_date += 1 - # end + end + end + + # date_range && reserved_dates + day_taken = date_range.map do |date| + reserved_dates.include? date + end + + if day_taken.all? {|word| word == false} + @room_available = room end end - # binding.pry - # return room_available - end #@room each + # should instead use find_vacancies_on_date method? + # @room_calendar.each do |room, reserved_dates| + # if reserved_dates.empty? + # room_available = room + # else + # search_date = start_date + # while search_date < end_date + # # search_date.each do |search_date| + # if reserved_dates.include? search_date + # next + # else + # room_available = room + # exit + # # reserved_dates.each do |reserved_dates + # end + # search_date += 1 + # # end + # + # end + # end - new_reservation = Reservation.new(room_available, guest_name: guest_name, start_date: start_date, end_date: end_date) + # binding.pry + # # return room_available + # end #@room each + # room_available = undefined + end + # binding.pry + new_reservation = Reservation.new(@room_available, guest_name: guest_name, start_date: start_date, end_date: end_date) add_reservation(new_reservation) add_reservation_to_calendar(new_reservation) - # binding.pry return new_reservation end # def reserve_available_room - - end # of class BookingManager end # of module Hotel From d261b587e263b740235e713007de198579f0ae5c Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Mon, 10 Sep 2018 02:13:24 -0700 Subject: [PATCH 68/87] Delete surplus comments --- lib/reservation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 0e7378ba9..f16c43232 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -4,7 +4,7 @@ class Reservation attr_accessor :guest_name, :start_date, :end_date, :cost_per_night def initialize(room, guest_name:, start_date:, end_date:, cost_per_night: 200.00) - @room = room.number + @room = room @guest_name = guest_name check_dates(start_date, end_date) @start_date = Date.parse(start_date) From 41af7f5b4b5287160bec9e3f342a35c1f77569b4 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Mon, 10 Sep 2018 02:44:34 -0700 Subject: [PATCH 69/87] Deleted extra comments. Changed booking_manager_spec test Room.new instances to hotel.rooms call --- lib/booking_manager.rb | 3 +- spec/booking_manager_spec.rb | 90 +++++++++++++++++------------------- 2 files changed, 45 insertions(+), 48 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 0fe791b1e..5a3150158 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -64,8 +64,9 @@ def add_reservation_to_calendar(reservation) reservation.number_nights.times do @room_calendar[reservation.room][date] = reservation # dependency date += 1 - end + end +# binding.pry return @room_calendar end diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 245532b59..b7aaa9e1c 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -5,7 +5,7 @@ it "creates an instance of BookingManager" do manager = Hotel::BookingManager.new(10) expect(manager).must_be_kind_of Hotel::BookingManager - end # of it instance bookingmanager + end it "creates the proper structures for instance variables instantiated" do hotel_rooms = Hotel::BookingManager.new(20) @@ -13,14 +13,7 @@ expect(hotel_rooms.rooms).must_be_kind_of Array expect(hotel_rooms.reservations).must_be_kind_of Array end - - # it "assigns instance variables to values returned from class methods" do - # hotel_rooms = Hotel::BookingManager.new(5) - # - # expect(hotel_rooms.rooms).must_equal hotel_rooms.populate_room_list(5) - # expect(hotel_rooms.reservations).must_equal hotel_rooms.make_reservation_list - # end - end # of initializer describe + end describe "populate_room_list method" do @@ -29,7 +22,7 @@ expect(new_rooms.populate_room_list(10)).must_be_kind_of Array expect(new_rooms.populate_room_list(10).first).must_be_instance_of Hotel::Room expect(new_rooms.populate_room_list(10).last).must_be_instance_of Hotel::Room - end # of array Room instance it + end it "assigns numbers to rooms consecutively as instantiated" do x = 15 @@ -46,7 +39,7 @@ hotel_rooms = Hotel::BookingManager.new(x) expect(hotel_rooms.populate_room_list(x).length).must_equal x end - end # of room load methods + end describe "make_reservation_list method" do @@ -59,7 +52,7 @@ hotel_rooms = Hotel::BookingManager.new(5) expect(hotel_rooms.make_reservation_list).must_be_empty end - end # of reservation list test do + end describe "list_reservations method" do it "returns an array" do @@ -96,7 +89,7 @@ end it "adds new instance of Reservation to reservations array" do - room = Hotel::Room.new(1) + room = @hotel_rooms.rooms[1] another_booking = Hotel::Reservation.new(room, guest_name: "Polly Pocket", start_date: "May 10, 2018", end_date: "May 12, 2018") @hotel_rooms.add_reservation(another_booking) @@ -104,53 +97,56 @@ expect(@hotel_rooms.reservations.last.guest_name).must_equal "Polly Pocket" end - end # of add_reservation method + end describe "add_reservation_to_calendar method" do - it "creates a hash with room number as key and dates as hash" do + it "creates a hash with room instance as key and dates as hash" do hotel = Hotel::BookingManager.new(3) - room = Hotel::Room.new(3) + # room = Hotel::Room.new(3) + room = hotel.rooms.first another_booking = Hotel::Reservation.new(room, guest_name: "Kim Possible", start_date: "June 11, 2018", end_date: "June 14, 2018") + + hotel.add_reservation_to_calendar(another_booking) expect(hotel.add_reservation_to_calendar(another_booking)).must_be_kind_of Hash - expect(hotel.room_calendar[3]).must_include Date.parse("June 11, 2018") - expect(hotel.room_calendar[3].length).must_equal another_booking.number_nights - end # end of add reservation to calendar method hash room key it - end # of add reservation to calendar method + expect(hotel.room_calendar[room]).must_include (Date.parse("June 11, 2018")) + expect(hotel.room_calendar[room].length).must_equal another_booking.number_nights + end + end describe "get_reservation_cost method" do it "returns the total cost of the reservation" do hotel = Hotel::BookingManager.new(3) - room = Hotel::Room.new(3) + room = hotel.rooms[3] booking = Hotel::Reservation.new(room, guest_name: "Tony Tonson", start_date: "June 10, 2018", end_date: "June 12, 2018") expect(hotel.get_reservation_cost(booking.cost_per_night, booking.number_nights)).must_be_close_to 400 - end # returns product it - end # of get_reservation_cost method" + end + end describe "find_reservations_on_date method" do it "returns all reservations on the desired date" do hotel = Hotel::BookingManager.new(5) - room1 = Hotel::Room.new(1) - room2 = Hotel::Room.new(2) - room3 = Hotel::Room.new(3) - booking1 = Hotel::Reservation.new(room1, guest_name: "Tony Blaze", start_date: "June 10, 2018", end_date: "June 12, 2018") + room1 = hotel.rooms[0] + room2 = hotel.rooms[1] + room3 = hotel.rooms[2] + booking1 = Hotel::Reservation.new(room1, guest_name: "Marsha Daze", start_date: "June 10, 2018", end_date: "June 12, 2018") booking2 = Hotel::Reservation.new(room2, guest_name: "Jessie Jade", start_date: "June 10, 2018", end_date: "June 14, 2018") - booking3 = Hotel::Reservation.new(room3, guest_name: "Jessie Jade", start_date: "June 14, 2018", end_date: "June 16, 2018") + booking3 = Hotel::Reservation.new(room3, guest_name: "Daria Jade", start_date: "June 14, 2018", end_date: "June 16, 2018") hotel.add_reservation_to_calendar(booking1) hotel.add_reservation_to_calendar(booking2) hotel.add_reservation_to_calendar(booking3) expect(hotel.find_reservations_on_date("June 11, 2018", hotel.room_calendar).length).must_equal 2 - end # of returns all reservations on date it - end # of find_reservations_on_date method + end + end describe "find_vacancies_on_date method" do before do @hotel = Hotel::BookingManager.new(5) - room1 = Hotel::Room.new(1) - room2 = Hotel::Room.new(2) - @room3 = Hotel::Room.new(3) - booking1 = Hotel::Reservation.new(room1, guest_name: "Tony Blaze", start_date: "June 10, 2018", end_date: "June 12, 2018") + room1 = @hotel.rooms[0] + room2 = @hotel.rooms[1] + @room3 = @hotel.rooms[2] + booking1 = Hotel::Reservation.new(room1, guest_name: "Tonya Blaze", start_date: "June 10, 2018", end_date: "June 12, 2018") booking2 = Hotel::Reservation.new(room2, guest_name: "Jane James", start_date: "June 10, 2018", end_date: "June 14, 2018") booking3 = Hotel::Reservation.new(@room3, guest_name: "Jessie Jade", start_date: "June 14, 2018", end_date: "June 16, 2018") @hotel.add_reservation_to_calendar(booking1) @@ -161,11 +157,11 @@ it "returns array of rooms without reservations on given date" do expect(@hotel.find_vacancies_on_date("June 10, 2018", @hotel.room_calendar).length).must_equal 3 expect(@hotel.find_vacancies_on_date("June 17, 2018", @hotel.room_calendar).length).must_equal 5 - end # of find vacancies it + end it "returns message of no vacancies when all rooms are reserved" do - room4 = Hotel::Room.new(4) - room5 = Hotel::Room.new(5) + room4 = @hotel.rooms[3] + room5 = @hotel.rooms[4] booking4 = Hotel::Reservation.new(@room3, guest_name: "Lady Day", start_date: "June 10, 2018", end_date: "June 11, 2018") booking5 = Hotel::Reservation.new(room4, guest_name: "Horis Who", start_date: "June 08, 2018", end_date: "June 14, 2018") @@ -176,32 +172,32 @@ @hotel.add_reservation_to_calendar(booking6) expect(@hotel.find_vacancies_on_date("June 10, 2018", @hotel.room_calendar)).must_be_kind_of String - end # no find_vacancies no vacancy it - end # of find vacancies on date method + end + end describe "reserve_available_room method" do before do @hotel = Hotel::BookingManager.new(5) - room4 = Hotel::Room.new(4) - room5 = Hotel::Room.new(5) + room4 = @hotel.rooms[3] + room5 = @hotel.rooms[4] booking5 = Hotel::Reservation.new(room4, guest_name: "Horis Who", start_date: "June 08, 2018", end_date: "June 14, 2018") booking6 = Hotel::Reservation.new(room5, guest_name: "Dorian Damian", start_date: "June 06, 2018", end_date: "June 11, 2018") @hotel.add_reservation(booking5) @hotel.add_reservation(booking6) - # + @number_prior_reservations = @hotel.reservations.length @hotel.reserve_available_room("Donna Foster", "January 02, 2019", "January 08, 2019") end - it "only allows reservations for rooms/dates not already reserved" do - - end + # it "only allows reservations for rooms/dates not already reserved" do + # + # end it "reserves available room for given date range" do expect(@hotel.reservations.length).must_equal @number_prior_reservations + 1 end - end # of reserve available room method + end -end # end of describe BookingManager class +end From 46c1597213f315a4c2a634e2d3d37d403c41424e Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Mon, 10 Sep 2018 02:59:36 -0700 Subject: [PATCH 70/87] Add refactors.txt file of possible future changes --- lib/booking_manager.rb | 20 +++++++------------- refactors.txt | 8 ++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 refactors.txt diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 5a3150158..551d0d5f2 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -33,16 +33,10 @@ def make_reservation_list return reservations end - # Create list of rooms with reserved dates. Change name? - def make_room_calendar(number) # combine with @rooms? + # Create list of rooms with reserved dates. + def make_room_calendar(number) @room_calendar = {} - # - # number.times do |num| - # dates_reserved = {} #[] - # @room_calendar[num+1] = dates_reserved - # end - # return @room_calendar @rooms.each do |room| dates_reserved = {} @room_calendar[room] = dates_reserved @@ -104,8 +98,8 @@ def find_reservations_on_date(date, calendar) else next end - end # of info each - end # end of calendar each + end + end # Add return message for no reservations found? return found_reservations end @@ -193,7 +187,7 @@ def reserve_available_room(guest_name, start_date, end_date) add_reservation(new_reservation) add_reservation_to_calendar(new_reservation) return new_reservation - end # def reserve_available_room + end - end # of class BookingManager -end # of module Hotel + end +end diff --git a/refactors.txt b/refactors.txt new file mode 100644 index 000000000..346194e6b --- /dev/null +++ b/refactors.txt @@ -0,0 +1,8 @@ +Possible changes to Hotel: +- Reduce dependency of method for making Reservation on reserve instance variables? +- Split some of Hotel into smaller methods (like reserve_available_room) +- Do some of the methods have overlapping but contradictory options? Combine or link. (ex: @reservations & @room_calendar) +- Change name for BookingManager instance(s) in tests? Sometimes listed as "hotel", other times "manager", etc. +- Check more of edge cases +- Too many variables with 'reservation' in them? +- Make date handling a method (or two?) From d8a5ede89c87f92669a731f73087a9f4bf100c5a Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Mon, 10 Sep 2018 03:39:43 -0700 Subject: [PATCH 71/87] Delete unneeded loop in reserve_available method --- lib/booking_manager.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 551d0d5f2..757d43bb4 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -141,10 +141,10 @@ def reserve_available_room(guest_name, start_date, end_date) search_date = res_start_date until search_date > res_end_date - search_date.each do |search_date| + # search_date.each do |search_date| date_range << search_date search_date += 1 - end + # end end # date_range && reserved_dates @@ -190,4 +190,4 @@ def reserve_available_room(guest_name, start_date, end_date) end end -end +end From b9047e261eb3ee930bf2efe31d1ebffe268688fb Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Mon, 10 Sep 2018 03:40:17 -0700 Subject: [PATCH 72/87] Add refactor note on overwriting --- refactors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/refactors.txt b/refactors.txt index 346194e6b..f07b8015a 100644 --- a/refactors.txt +++ b/refactors.txt @@ -6,3 +6,4 @@ Possible changes to Hotel: - Check more of edge cases - Too many variables with 'reservation' in them? - Make date handling a method (or two?) +- Add check that rooms are not overwritten From 304fb988445f4ed2858a8f3fcab739eaf5932fe6 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Mon, 10 Sep 2018 03:42:04 -0700 Subject: [PATCH 73/87] Add test for reserve_available_room --- spec/booking_manager_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index b7aaa9e1c..88f072a2a 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -198,6 +198,17 @@ it "reserves available room for given date range" do expect(@hotel.reservations.length).must_equal @number_prior_reservations + 1 end + + it "iterates through rooms to find available room" do + room2 = @hotel.rooms[1] + booking2 = Hotel::Reservation.new(room2, guest_name: "Joe Jeans", start_date: "June 08, 2018", end_date: "June 14, 2018") + @hotel.add_reservation(booking2) + number_reserved = @hotel.reservations.length + + @hotel.reserve_available_room("Lisel Wallace", "June 08, 2018", "June 13, 2018") + # expect(@hotel.reservations).must_include "Lisel Wallace" + expect(@hotel.reservations.length).must_equal number_reserved + 1 + end end end From 1d0f3cc3309f3988f238d6c871ce56f892e36ec8 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 11 Sep 2018 22:24:49 -0700 Subject: [PATCH 74/87] Add tests for BookingManager#determine_date_range and BookingManager#find_vacancies_in_date_range --- spec/booking_manager_spec.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 88f072a2a..7746eca2a 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -211,4 +211,36 @@ end end + describe "determine_date_range method" do + before do + @bookingsystem = Hotel::BookingManager.new(5) + @range = @bookingsystem.determine_date_range("July 10, 2000", "July 15, 2000") + end + + it "creates array of Date instances" do + expect(@range.length).must_equal 6 + expect(@range.first).must_be_instance_of Date + end + + it "includes the correct dates" do + expect(@range.first.to_s).must_match /2000-07-10/ + expect(@range.last.to_s).must_match /2000-07-15/ + end + end + + describe "find_vacancies_in_date_range method" do + before do + @bookingsystem = Hotel::BookingManager.new(5) + room = @bookingsystem.rooms[0] + booking = Hotel::Reservation.new(room, guest_name: "Mary Poppins", start_date: "June 08, 2018", end_date: "June 14, 2018") + @bookingsystem.add_reservation_to_calendar(booking) + @found_vacancies = @bookingsystem.find_vacancies_in_date_range("June 10, 2018", "June 12, 2018") + end + + it "returns array of Room instances" do + expect(@found_vacancies.length).must_equal 4 + + end + + end end From a4cfa15f0381915598005c9b9d085b22be3997c1 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 11 Sep 2018 22:26:17 -0700 Subject: [PATCH 75/87] Add BookingManager#determine_date_range and BookingManager#find_vacancies_in_date_range --- lib/booking_manager.rb | 115 +++++++++++++++++++++++++---------------- 1 file changed, 70 insertions(+), 45 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 757d43bb4..b4532369f 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -119,6 +119,48 @@ def find_vacancies_on_date(date, calendar) return found_vacancies.empty? ? no_vacancies_message: found_vacancies end + + def determine_date_range(start_date, end_date) + check_dates(start_date, end_date) + + res_start_date = Date.parse(start_date) + res_end_date = Date.parse(end_date) + + date_range = [] + search_date = res_start_date + + until search_date > res_end_date + date_range << search_date + search_date += 1 + end + return date_range + end + + + def find_vacancies_in_date_range(start_date, end_date) + check_dates(start_date, end_date) + rooms_available_in_date_range = [] + + ## FINISH & TEST TEST TEST + @room_calendar.each do |room, reserved_dates| + if reserved_dates.empty? + rooms_available_in_date_range << room + else + # iterate through each room. if none match, add room to list of vacancies + date_range = determine_date_range(start_date, end_date) + + if (reserved_dates.keys && date_range).length > 0 + next + else + rooms_available_in_date_range << room + end + + end + end + + return rooms_available_in_date_range + end + def no_vacancies_message return "There are no vacancies for the given date range." end @@ -128,59 +170,42 @@ def reserve_available_room(guest_name, start_date, end_date) check_dates(start_date, end_date) @room_available = 0 - res_start_date = Date.parse(start_date) - res_end_date = Date.parse(end_date) - @room_calendar.each do |room, reserved_dates| if reserved_dates.empty? @room_available = room end - unless reserved_dates.empty? - date_range = [] - search_date = res_start_date - - until search_date > res_end_date - # search_date.each do |search_date| - date_range << search_date - search_date += 1 - # end - end + date_range = determine_date_range(start_date, end_date) - # date_range && reserved_dates - day_taken = date_range.map do |date| - reserved_dates.include? date - end + day_taken = date_range.map do |date| + reserved_dates.include? date + end - if day_taken.all? {|word| word == false} - @room_available = room - end + if day_taken.all? {|word| word == false} + @room_available = room end - # should instead use find_vacancies_on_date method? - # @room_calendar.each do |room, reserved_dates| - # if reserved_dates.empty? - # room_available = room - # else - # search_date = start_date - # while search_date < end_date - # # search_date.each do |search_date| - # if reserved_dates.include? search_date - # next - # else - # room_available = room - # exit - # # reserved_dates.each do |reserved_dates - # end - # search_date += 1 - # # end - # - # end - # end - - # binding.pry - # # return room_available - # end #@room each - # room_available = undefined + # end + # should instead use find_vacancies_on_date method? + # @room_calendar.each do |room, reserved_dates| + # if reserved_dates.empty? + # room_available = room + # else + # search_date = start_date + # while search_date < end_date + # # search_date.each do |search_date| + # if reserved_dates.include? search_date + # next + # else + # room_available = room + # exit + # # reserved_dates.each do |reserved_dates + # end + # search_date += 1 + # # end + # + # end + # end + end # binding.pry new_reservation = Reservation.new(@room_available, guest_name: guest_name, start_date: start_date, end_date: end_date) From abf9c23cc53fe7bab485d03fa19f06b59dc37df9 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 11 Sep 2018 22:39:33 -0700 Subject: [PATCH 76/87] Edit refactors list --- refactors.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/refactors.txt b/refactors.txt index f07b8015a..4a5c155de 100644 --- a/refactors.txt +++ b/refactors.txt @@ -1,9 +1,8 @@ Possible changes to Hotel: - Reduce dependency of method for making Reservation on reserve instance variables? - Split some of Hotel into smaller methods (like reserve_available_room) -- Do some of the methods have overlapping but contradictory options? Combine or link. (ex: @reservations & @room_calendar) -- Change name for BookingManager instance(s) in tests? Sometimes listed as "hotel", other times "manager", etc. +- Combine methods that have overlapping but contradictory options? Combine or link. (ex: @reservations & @room_calendar) +- Change name for BookingManager instance(s) in tests? Sometimes listed as "hotel", other times "manager", etc. Change all to BookingSystem? - Check more of edge cases -- Too many variables with 'reservation' in them? -- Make date handling a method (or two?) -- Add check that rooms are not overwritten +- Too many variables with 'reservation' in title? +- Add check that rooms are not overwritten From 7e47e4c8453bf06b90bba073d9382288879f58d8 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 11 Sep 2018 22:40:29 -0700 Subject: [PATCH 77/87] Delete surplus definition end comments --- lib/reservation.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index f16c43232..ac4dad07a 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -11,7 +11,7 @@ def initialize(room, guest_name:, start_date:, end_date:, cost_per_night: 200.00 @end_date = Date.parse(end_date) @cost_per_night = cost_per_night @number_nights = (@end_date - @start_date).to_i - end # of initialize method + end def check_dates(start_date, end_date) if start_date > end_date @@ -19,5 +19,5 @@ def check_dates(start_date, end_date) end end - end# of class Reservation -end #of Hotel module + end +end From c57e111f775516995e07aa8f738192dcb6d913ed Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 11 Sep 2018 22:55:46 -0700 Subject: [PATCH 78/87] Add assertion to test for BookingManager#find_vacancies_in_date_range --- lib/booking_manager.rb | 40 ++++++++++++++++++++++-------------- spec/booking_manager_spec.rb | 8 ++++++-- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index b4532369f..199451933 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -27,12 +27,14 @@ def populate_room_list(number_rooms) return rooms end + # Create array to store all of reservations def make_reservation_list reservations = [] return reservations end + # Create list of rooms with reserved dates. def make_room_calendar(number) @room_calendar = {} @@ -51,6 +53,7 @@ def add_reservation(reservation) @reservations << reservation end + # Add reservation date range to hash of room reserved dates def add_reservation_to_calendar(reservation) date = reservation.start_date @@ -58,18 +61,37 @@ def add_reservation_to_calendar(reservation) reservation.number_nights.times do @room_calendar[reservation.room][date] = reservation # dependency date += 1 - end # binding.pry return @room_calendar end + + # Check if date range given is valid - start must be before end def check_dates(start_date, end_date) if start_date > end_date raise ArgumentError.new "Invalid date range. Start date must be before end date, both in format of 'Month dd, yyyy'. " end end + + # Create array of all dates from start date to end date + def determine_date_range(start_date, end_date) + check_dates(start_date, end_date) + + res_start_date = Date.parse(start_date) + res_end_date = Date.parse(end_date) + + date_range = [] + search_date = res_start_date + + until search_date > res_end_date + date_range << search_date + search_date += 1 + end + return date_range + end + # Method to list all reservation instances def list_reservations return @reservations @@ -81,12 +103,14 @@ def list_rooms return @rooms end + # Method to get total cost of reservation def get_reservation_cost(nights, cost_per_night) total_cost = nights * cost_per_night return total_cost end + # Return array reservations with matching date from room calendar hash def find_reservations_on_date(date, calendar) search_date = Date.parse(date) found_reservations = [] @@ -120,21 +144,7 @@ def find_vacancies_on_date(date, calendar) end - def determine_date_range(start_date, end_date) - check_dates(start_date, end_date) - - res_start_date = Date.parse(start_date) - res_end_date = Date.parse(end_date) - - date_range = [] - search_date = res_start_date - until search_date > res_end_date - date_range << search_date - search_date += 1 - end - return date_range - end def find_vacancies_in_date_range(start_date, end_date) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 7746eca2a..525ad692a 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -237,9 +237,13 @@ @found_vacancies = @bookingsystem.find_vacancies_in_date_range("June 10, 2018", "June 12, 2018") end - it "returns array of Room instances" do + it "returns the correct number of vacant rooms" do expect(@found_vacancies.length).must_equal 4 - + end + + it "returns an array of Room instances" do + expect(@found_vacancies.first).must_be_instance_of Hotel::Room + expect(@found_vacancies.last).must_be_instance_of Hotel::Room end end From 30cfe706dbbcbbe8d3bff8fae6a7ee991f2b92e5 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 11 Sep 2018 23:14:59 -0700 Subject: [PATCH 79/87] Refactor reserve_available_room with find_vacancies_in_date_range method --- lib/booking_manager.rb | 52 ++++-------------------------------------- 1 file changed, 4 insertions(+), 48 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 199451933..227f028bb 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -144,33 +144,27 @@ def find_vacancies_on_date(date, calendar) end - - - def find_vacancies_in_date_range(start_date, end_date) check_dates(start_date, end_date) rooms_available_in_date_range = [] - ## FINISH & TEST TEST TEST @room_calendar.each do |room, reserved_dates| if reserved_dates.empty? rooms_available_in_date_range << room else - # iterate through each room. if none match, add room to list of vacancies date_range = determine_date_range(start_date, end_date) - if (reserved_dates.keys && date_range).length > 0 next else rooms_available_in_date_range << room end - end end return rooms_available_in_date_range end + def no_vacancies_message return "There are no vacancies for the given date range." end @@ -178,50 +172,12 @@ def no_vacancies_message def reserve_available_room(guest_name, start_date, end_date) check_dates(start_date, end_date) - @room_available = 0 + available_rooms = find_vacancies_in_date_range(start_date, end_date) - @room_calendar.each do |room, reserved_dates| - if reserved_dates.empty? - @room_available = room - end - - date_range = determine_date_range(start_date, end_date) - - day_taken = date_range.map do |date| - reserved_dates.include? date - end - - if day_taken.all? {|word| word == false} - @room_available = room - end - # end - # should instead use find_vacancies_on_date method? - # @room_calendar.each do |room, reserved_dates| - # if reserved_dates.empty? - # room_available = room - # else - # search_date = start_date - # while search_date < end_date - # # search_date.each do |search_date| - # if reserved_dates.include? search_date - # next - # else - # room_available = room - # exit - # # reserved_dates.each do |reserved_dates - # end - # search_date += 1 - # # end - # - # end - # end - - end - # binding.pry - new_reservation = Reservation.new(@room_available, guest_name: guest_name, start_date: start_date, end_date: end_date) + new_reservation = Reservation.new(available_rooms.first, guest_name: guest_name, start_date: start_date, end_date: end_date) add_reservation(new_reservation) add_reservation_to_calendar(new_reservation) - return new_reservation + return new_reservation #unneeded? end end From 3f0e697061a2a34e0da258dbac588f7a09881a27 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 25 Sep 2018 14:00:14 -0700 Subject: [PATCH 80/87] Add design activity file --- design-activity.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 design-activity.md diff --git a/design-activity.md b/design-activity.md new file mode 100644 index 000000000..e69de29bb From 30052542af164125a632775e789b77643c290941 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 25 Sep 2018 15:07:29 -0700 Subject: [PATCH 81/87] Add answers to design activity questions --- design-activity.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/design-activity.md b/design-activity.md index e69de29bb..e195e994a 100644 --- a/design-activity.md +++ b/design-activity.md @@ -0,0 +1,24 @@ +* What classes does each implementation include? Are the lists the same? | Each has the same classes, CartEntry, ShoppingCart, and Order, but the methods have been reorganized in the second implementation. +* Write down a sentence to describe each class. | + * CartEntry handles an item added, taking in as parameters its unit price and quantity. It also calculates the price of that CartEntry instance. + * ShoppingCart manages the list of entries and price of all entries combined. + * Order stores the constant SALES_TAX and totals the sum of the ShoppingCart plus Sales tax. +* How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper. + * Order totals the cost of the ShoppingCart which has a collection of instances of CartEntry. +* What data does each class store? How (if at all) does this differ between the two implementations? + * CartEntry stores the instance variables unit_price and quantity, which are only used in CartEntry. In the second implementation, it does not have an attribute accessor. + * ShoppingCart stores the instance variable entries which is a collection of CartEntry instances. In the second implementation, it does not have an attribute accessor. + * Order stores the constant SALES_TAX. It stores the instance of ShoppingCart. +* What methods does each class have? How (if at all) does this differ between the two implementations? + * Each has an initialize, but they no longer as attribute reader/writers. The Order total_price method no longer calls instance variables from other classes. It only calls an instance variable of ShoppingCart, which was initialized in Order. +* 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? + * Computing the price is retained in Order. + * Does total_price directly manipulate the instance variables of other classes? + * No, only those directly called in Order. +* If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify? + * This would be easier to change in Implementation B because we would only need to change what is passed into CartEntry unit price and/or quantity. +* Which implementation better adheres to the single responsibility principle? + * Implementation B better adheres to single responsibility because each class only operates on and calculates its own instance variables. +* Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? + * Implementation B is more loosely coupled. It has less instances of directly calling/naming an instance variable or attribute from other classes or variables. From 835f75796ef95afb73f159866a67654acd31a940 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 25 Sep 2018 15:32:34 -0700 Subject: [PATCH 82/87] Add discussion of Hotel design changes --- design-activity.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/design-activity.md b/design-activity.md index e195e994a..246e9ab4d 100644 --- a/design-activity.md +++ b/design-activity.md @@ -1,3 +1,5 @@ +## Evaluating Responsibility + * What classes does each implementation include? Are the lists the same? | Each has the same classes, CartEntry, ShoppingCart, and Order, but the methods have been reorganized in the second implementation. * Write down a sentence to describe each class. | * CartEntry handles an item added, taking in as parameters its unit price and quantity. It also calculates the price of that CartEntry instance. @@ -21,4 +23,8 @@ * Which implementation better adheres to the single responsibility principle? * Implementation B better adheres to single responsibility because each class only operates on and calculates its own instance variables. * Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? - * Implementation B is more loosely coupled. It has less instances of directly calling/naming an instance variable or attribute from other classes or variables. + * Implementation B is more loosely coupled. It has less instances of directly calling/naming an instance variable or attribute from other classes or variables. + +## Revisiting Hotel +Identify one place in your Hotel project where a class takes on multiple roles, or directly modifies the attributes of another class. Describe in design-activity.md what changes you would need to make to improve this design, and how the resulting design would be an improvement. +BookingManager class takes on multiple roles, some of which are acting on (or creating) attributes of class Reservation. I would need to move several of the functions from BookingManager to Reservation. Making this change would allow my code to more so follow Single Responsibility. From 0b72d5cf400b7f3d17be305f266260600179cf41 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 25 Sep 2018 15:33:15 -0700 Subject: [PATCH 83/87] Include comment about combining reservation methods in BookingManager --- lib/booking_manager.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 227f028bb..6e9161750 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -49,7 +49,7 @@ def make_room_calendar(number) # Method to add a reservation to list of reservations - def add_reservation(reservation) + def add_reservation(reservation) #combine with add_reservation_to_calendar? @reservations << reservation end From 3db140a58d326731e25d4464d029178e3232aab5 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 25 Sep 2018 15:50:58 -0700 Subject: [PATCH 84/87] Move get_reservation_cost from BookingManager to Reservation class --- lib/booking_manager.rb | 11 +++++------ lib/reservation.rb | 8 +++++++- spec/booking_manager_spec.rb | 18 +++++++++--------- spec/reservation_spec.rb | 9 +++++++++ 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 6e9161750..1286804e1 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -103,12 +103,11 @@ def list_rooms return @rooms end - - # Method to get total cost of reservation - def get_reservation_cost(nights, cost_per_night) - total_cost = nights * cost_per_night - return total_cost - end + # # Method to get total cost of reservation + # def get_reservation_cost(nights, cost_per_night) + # total_cost = nights * cost_per_night + # return total_cost + # end # Return array reservations with matching date from room calendar hash def find_reservations_on_date(date, calendar) diff --git a/lib/reservation.rb b/lib/reservation.rb index ac4dad07a..971b452b9 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -11,7 +11,7 @@ def initialize(room, guest_name:, start_date:, end_date:, cost_per_night: 200.00 @end_date = Date.parse(end_date) @cost_per_night = cost_per_night @number_nights = (@end_date - @start_date).to_i - end + end def check_dates(start_date, end_date) if start_date > end_date @@ -19,5 +19,11 @@ def check_dates(start_date, end_date) end end + # # Method to get total cost of reservation + def get_reservation_cost + total_cost = @number_nights * @cost_per_night + return total_cost + end + end end diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 525ad692a..40efb7f67 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -113,15 +113,15 @@ end end - describe "get_reservation_cost method" do - it "returns the total cost of the reservation" do - hotel = Hotel::BookingManager.new(3) - room = hotel.rooms[3] - booking = Hotel::Reservation.new(room, guest_name: "Tony Tonson", start_date: "June 10, 2018", end_date: "June 12, 2018") - - expect(hotel.get_reservation_cost(booking.cost_per_night, booking.number_nights)).must_be_close_to 400 - end - end + # describe "get_reservation_cost method" do + # it "returns the total cost of the reservation" do + # hotel = Hotel::BookingManager.new(3) + # room = hotel.rooms[3] + # booking = Hotel::Reservation.new(room, guest_name: "Tony Tonson", start_date: "June 10, 2018", end_date: "June 12, 2018") + # + # expect(hotel.get_reservation_cost(booking.cost_per_night, booking.number_nights)).must_be_close_to 400 + # end + # end describe "find_reservations_on_date method" do it "returns all reservations on the desired date" do diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb index 5ed4d3d3e..410ebfffe 100644 --- a/spec/reservation_spec.rb +++ b/spec/reservation_spec.rb @@ -21,5 +21,14 @@ end # of initialize method + describe "get_reservation_cost method" do + it "returns the total cost of the reservation" do + hotel = Hotel::BookingManager.new(5) + room = hotel.rooms.first + booking = Hotel::Reservation.new(room, guest_name: "Ilona Illari", start_date: "June 10, 2018", end_date: "June 12, 2018") + + expect(booking.get_reservation_cost).must_be_close_to 400 + end + end end # of class Reservation From 320840c756f9f248da357ec537395aef8f91b64c Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 25 Sep 2018 16:41:18 -0700 Subject: [PATCH 85/87] Move date_range in find_vacancies to before loop. Comment out no_vacancies message --- lib/booking_manager.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 1286804e1..e1902eec2 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -109,6 +109,7 @@ def list_rooms # return total_cost # end + # Return array reservations with matching date from room calendar hash def find_reservations_on_date(date, calendar) search_date = Date.parse(date) @@ -139,19 +140,20 @@ def find_vacancies_on_date(date, calendar) end end - return found_vacancies.empty? ? no_vacancies_message: found_vacancies + return found_vacancies + #.empty? ? no_vacancies_message: found_vacancies end def find_vacancies_in_date_range(start_date, end_date) check_dates(start_date, end_date) + date_range = determine_date_range(start_date, end_date) rooms_available_in_date_range = [] @room_calendar.each do |room, reserved_dates| if reserved_dates.empty? rooms_available_in_date_range << room else - date_range = determine_date_range(start_date, end_date) if (reserved_dates.keys && date_range).length > 0 next else From e2a1ab2c5d031240d871ae5cdaf014dba3dacd90 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 25 Sep 2018 16:49:26 -0700 Subject: [PATCH 86/87] Comment out no_vacancies method and test --- lib/booking_manager.rb | 6 +++--- spec/booking_manager_spec.rb | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index e1902eec2..5a43ba506 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -166,9 +166,9 @@ def find_vacancies_in_date_range(start_date, end_date) end - def no_vacancies_message - return "There are no vacancies for the given date range." - end + # def no_vacancies_message + # return "There are no vacancies for the given date range." + # end def reserve_available_room(guest_name, start_date, end_date) diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index 40efb7f67..bf3c4743c 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -159,20 +159,20 @@ expect(@hotel.find_vacancies_on_date("June 17, 2018", @hotel.room_calendar).length).must_equal 5 end - it "returns message of no vacancies when all rooms are reserved" do - room4 = @hotel.rooms[3] - room5 = @hotel.rooms[4] - - booking4 = Hotel::Reservation.new(@room3, guest_name: "Lady Day", start_date: "June 10, 2018", end_date: "June 11, 2018") - booking5 = Hotel::Reservation.new(room4, guest_name: "Horis Who", start_date: "June 08, 2018", end_date: "June 14, 2018") - booking6 = Hotel::Reservation.new(room5, guest_name: "Dorian Damian", start_date: "June 06, 2018", end_date: "June 11, 2018") - - @hotel.add_reservation_to_calendar(booking4) - @hotel.add_reservation_to_calendar(booking5) - @hotel.add_reservation_to_calendar(booking6) - - expect(@hotel.find_vacancies_on_date("June 10, 2018", @hotel.room_calendar)).must_be_kind_of String - end + # it "returns message of no vacancies when all rooms are reserved" do + # room4 = @hotel.rooms[3] + # room5 = @hotel.rooms[4] + # + # booking4 = Hotel::Reservation.new(@room3, guest_name: "Lady Day", start_date: "June 10, 2018", end_date: "June 11, 2018") + # booking5 = Hotel::Reservation.new(room4, guest_name: "Horis Who", start_date: "June 08, 2018", end_date: "June 14, 2018") + # booking6 = Hotel::Reservation.new(room5, guest_name: "Dorian Damian", start_date: "June 06, 2018", end_date: "June 11, 2018") + # + # @hotel.add_reservation_to_calendar(booking4) + # @hotel.add_reservation_to_calendar(booking5) + # @hotel.add_reservation_to_calendar(booking6) + # + # expect(@hotel.find_vacancies_on_date("June 10, 2018", @hotel.room_calendar)).must_be_kind_of String + # end end describe "reserve_available_room method" do From d2cbed881e22189deaa6a8a50c813d87a4bd31d3 Mon Sep 17 00:00:00 2001 From: Katricia Smith Date: Tue, 25 Sep 2018 17:16:59 -0700 Subject: [PATCH 87/87] Combine add_reservation method with add_reservation_to_calendar method --- lib/booking_manager.rb | 10 ++++++---- spec/booking_manager_spec.rb | 18 ++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/booking_manager.rb b/lib/booking_manager.rb index 5a43ba506..8ec0d3be5 100644 --- a/lib/booking_manager.rb +++ b/lib/booking_manager.rb @@ -49,19 +49,21 @@ def make_room_calendar(number) # Method to add a reservation to list of reservations - def add_reservation(reservation) #combine with add_reservation_to_calendar? - @reservations << reservation - end + # def add_reservation(reservation) #combine with add_reservation_to_calendar? + # @reservations << reservation + # end # Add reservation date range to hash of room reserved dates def add_reservation_to_calendar(reservation) date = reservation.start_date + @reservations << reservation reservation.number_nights.times do @room_calendar[reservation.room][date] = reservation # dependency date += 1 end + # binding.pry return @room_calendar end @@ -176,7 +178,7 @@ def reserve_available_room(guest_name, start_date, end_date) available_rooms = find_vacancies_in_date_range(start_date, end_date) new_reservation = Reservation.new(available_rooms.first, guest_name: guest_name, start_date: start_date, end_date: end_date) - add_reservation(new_reservation) + # add_reservation(new_reservation) add_reservation_to_calendar(new_reservation) return new_reservation #unneeded? end diff --git a/spec/booking_manager_spec.rb b/spec/booking_manager_spec.rb index bf3c4743c..04fec26b0 100644 --- a/spec/booking_manager_spec.rb +++ b/spec/booking_manager_spec.rb @@ -75,31 +75,29 @@ end end - describe "add_reservation method" do + describe "add_reservation_to_calendar method" do before do @hotel_rooms = Hotel::BookingManager.new(5) end it "increases the length of the reservations array by one" do old_number = @hotel_rooms.reservations.length - new_booking = "new reservation" + room = @hotel_rooms.rooms[2] + new_booking = Hotel::Reservation.new(room, guest_name: "Polly Pocket", start_date: "May 10, 2018", end_date: "May 12, 2018") - @hotel_rooms.add_reservation(new_booking) + @hotel_rooms.add_reservation_to_calendar(new_booking) expect(@hotel_rooms.reservations.length).must_equal old_number + 1 end it "adds new instance of Reservation to reservations array" do room = @hotel_rooms.rooms[1] another_booking = Hotel::Reservation.new(room, guest_name: "Polly Pocket", start_date: "May 10, 2018", end_date: "May 12, 2018") - @hotel_rooms.add_reservation(another_booking) + @hotel_rooms.add_reservation_to_calendar(another_booking) expect(@hotel_rooms.reservations.last).must_be_instance_of Hotel::Reservation expect(@hotel_rooms.reservations.last.guest_name).must_equal "Polly Pocket" end - end - - describe "add_reservation_to_calendar method" do it "creates a hash with room instance as key and dates as hash" do hotel = Hotel::BookingManager.new(3) # room = Hotel::Room.new(3) @@ -184,8 +182,8 @@ booking5 = Hotel::Reservation.new(room4, guest_name: "Horis Who", start_date: "June 08, 2018", end_date: "June 14, 2018") booking6 = Hotel::Reservation.new(room5, guest_name: "Dorian Damian", start_date: "June 06, 2018", end_date: "June 11, 2018") - @hotel.add_reservation(booking5) - @hotel.add_reservation(booking6) + @hotel.add_reservation_to_calendar(booking5) + @hotel.add_reservation_to_calendar(booking6) @number_prior_reservations = @hotel.reservations.length @hotel.reserve_available_room("Donna Foster", "January 02, 2019", "January 08, 2019") @@ -202,7 +200,7 @@ it "iterates through rooms to find available room" do room2 = @hotel.rooms[1] booking2 = Hotel::Reservation.new(room2, guest_name: "Joe Jeans", start_date: "June 08, 2018", end_date: "June 14, 2018") - @hotel.add_reservation(booking2) + @hotel.add_reservation_to_calendar(booking2) number_reserved = @hotel.reservations.length @hotel.reserve_available_room("Lisel Wallace", "June 08, 2018", "June 13, 2018")