From da1fe4924ea13de93212cba58544ccf1b28a34f2 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 4 Sep 2018 13:41:39 -0700 Subject: [PATCH 01/41] Add coverage directory to .gitignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5e1422c9c..c0ac3dc53 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ build-iPhoneSimulator/ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc +coverage From d4e674ee3c46cc1c784fe99b897b25cca7bf4269 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 4 Sep 2018 16:01:36 -0700 Subject: [PATCH 02/41] created room spec tests --- lib/reservations_manager.rb | 18 ++++++++++++++++++ lib/room.rb | 18 ++++++++++++++++++ spec/reservations_manager_spec.rb | 16 ++++++++++++++++ spec/room_spec.rb | 23 +++++++++++++++++++++++ spec/spec_helper.rb | 5 +++++ 5 files changed, 80 insertions(+) create mode 100644 lib/reservations_manager.rb create mode 100644 lib/room.rb create mode 100644 spec/reservations_manager_spec.rb create mode 100644 spec/room_spec.rb diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb new file mode 100644 index 000000000..a8de8d46f --- /dev/null +++ b/lib/reservations_manager.rb @@ -0,0 +1,18 @@ +# require 'pry' +# +# require_relative 'room' +# #reservations manager +# module Hotel +# class ReservationsManager +# attr_reader :rooms +# def initialize(number_of_rooms) +# @rooms = [] +# (1..number_of_rooms).each do |number| +# @rooms << Room.new(number) +# end +# +# @reservations =[] +# +# end +# end +# end diff --git a/lib/room.rb b/lib/room.rb new file mode 100644 index 000000000..450534774 --- /dev/null +++ b/lib/room.rb @@ -0,0 +1,18 @@ +require 'pry' + +module Hotel + class Room + attr_reader + def initialize(number) + @id = number + @reservations = [] + end + + def self.create_rooms(number_of_rooms) + rooms = [] + (1..number_of_rooms).each do |number| + @rooms << Room.new(number) + end + return rooms + end +end diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb new file mode 100644 index 000000000..15ff9a396 --- /dev/null +++ b/spec/reservations_manager_spec.rb @@ -0,0 +1,16 @@ +# require_relative 'spec_helper' +# require 'pry' +# +# describe "ReservationsManager" do +# describe "Initialize ReservationsManager" do +# it "is an instance of Hotel::ReservationsManager" do +# hotel_ada = Hotel::ReservationsManager.new(20) +# expect(hotel_ada).must_be_instance_of Hotel::ReservationsManager +# expect(hotel_ada.rooms.count).must_equal 20 +# expect(hotel_ada.rooms[0]).must_be_instance_of Hotel::Room +# expect(hotel_ada.rooms).must_be_kind_of Array +# end +# end +# +# describe "List all rooms " +# end diff --git a/spec/room_spec.rb b/spec/room_spec.rb new file mode 100644 index 000000000..de941c7e6 --- /dev/null +++ b/spec/room_spec.rb @@ -0,0 +1,23 @@ +require_relative 'spec_helper' +require 'pry' + +describe "Room Class" do + describe "Initialize Room" do + it "is an instance of Hotel::Room" do + + hotel_room = Hotel::Room.new(1) + expect(hotel_room).must_be_kind_of Hotel::Room + end + end + + describe "create_rooms" do + it "creates specified number of hotel rooms" do + hotel_ada = Hotel::Room.create_rooms(20) + expect(hotel_ada).must_be_instance_of Hotel::Room + expect(hotel_ada.rooms.count).must_equal 20 + expect(hotel_ada.rooms[0]).must_be_instance_of Hotel::Room + expect(hotel_ada.rooms).must_be_kind_of Array + end + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d1e3fdc8..035ac265a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,13 @@ +require 'simplecov' +SimpleCov.start require 'minitest' require 'minitest/autorun' require 'minitest/reporters' + # Add simplecov Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # Require_relative your lib files here! +require_relative '../lib/reservations_manager.rb' +require_relative '../lib/room.rb' From 9edc68c22a98c5ee280766ac8382e135350264e0 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 4 Sep 2018 16:25:27 -0700 Subject: [PATCH 03/41] Settled on reservations manager class --- lib/reservations_manager.rb | 36 +++++++++++++++---------------- lib/room.rb | 7 +----- spec/reservations_manager_spec.rb | 32 +++++++++++++-------------- spec/room_spec.rb | 17 +++++++-------- 4 files changed, 43 insertions(+), 49 deletions(-) diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index a8de8d46f..cec704c97 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -1,18 +1,18 @@ -# require 'pry' -# -# require_relative 'room' -# #reservations manager -# module Hotel -# class ReservationsManager -# attr_reader :rooms -# def initialize(number_of_rooms) -# @rooms = [] -# (1..number_of_rooms).each do |number| -# @rooms << Room.new(number) -# end -# -# @reservations =[] -# -# end -# end -# end +require 'pry' + +require_relative 'room' +#reservations manager +module Hotel + class ReservationsManager + attr_reader :rooms + def initialize(number_of_rooms) + @rooms = [] + (1..number_of_rooms).each do |number| + @rooms << Room.new(number) + end + + @reservations =[] + + end + end +end diff --git a/lib/room.rb b/lib/room.rb index 450534774..94eab41ea 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -8,11 +8,6 @@ def initialize(number) @reservations = [] end - def self.create_rooms(number_of_rooms) - rooms = [] - (1..number_of_rooms).each do |number| - @rooms << Room.new(number) - end - return rooms + end end diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 15ff9a396..52bd6ec48 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -1,16 +1,16 @@ -# require_relative 'spec_helper' -# require 'pry' -# -# describe "ReservationsManager" do -# describe "Initialize ReservationsManager" do -# it "is an instance of Hotel::ReservationsManager" do -# hotel_ada = Hotel::ReservationsManager.new(20) -# expect(hotel_ada).must_be_instance_of Hotel::ReservationsManager -# expect(hotel_ada.rooms.count).must_equal 20 -# expect(hotel_ada.rooms[0]).must_be_instance_of Hotel::Room -# expect(hotel_ada.rooms).must_be_kind_of Array -# end -# end -# -# describe "List all rooms " -# end +require_relative 'spec_helper' +require 'pry' + +describe "ReservationsManager" do + describe "Initialize ReservationsManager" do + it "is an instance of Hotel::ReservationsManager" do + hotel_ada = Hotel::ReservationsManager.new(20) + expect(hotel_ada).must_be_instance_of Hotel::ReservationsManager + expect(hotel_ada.rooms.count).must_equal 20 + expect(hotel_ada.rooms[0]).must_be_instance_of Hotel::Room + expect(hotel_ada.rooms).must_be_kind_of Array + end + end + + # describe "List all rooms " +end diff --git a/spec/room_spec.rb b/spec/room_spec.rb index de941c7e6..34b6aca79 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -10,14 +10,13 @@ end end - describe "create_rooms" do - it "creates specified number of hotel rooms" do - hotel_ada = Hotel::Room.create_rooms(20) - expect(hotel_ada).must_be_instance_of Hotel::Room - expect(hotel_ada.rooms.count).must_equal 20 - expect(hotel_ada.rooms[0]).must_be_instance_of Hotel::Room - expect(hotel_ada.rooms).must_be_kind_of Array - end - end + # describe "create_rooms" do + # it "creates specified number of hotel rooms" do + # hotel_ada = Hotel::Room.create_rooms(20) + # expect(hotel_ada).must_be_instance_of Hotel::Room + # expect(hotel_ada.rooms.count).must_equal 20 + # expect(hotel_ada.rooms[0]).must_be_instance_of Hotel::Room + # expect(hotel_ada.rooms).must_be_kind_of Array + end From f683f667b30f896981109a74992a506aee6ebfe1 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 4 Sep 2018 16:37:38 -0700 Subject: [PATCH 04/41] removed list method --- lib/reservations_manager.rb | 4 ++-- lib/room.rb | 2 -- spec/reservations_manager_spec.rb | 14 +++++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index cec704c97..80777ede7 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -10,9 +10,9 @@ def initialize(number_of_rooms) (1..number_of_rooms).each do |number| @rooms << Room.new(number) end - @reservations =[] - end + + end end diff --git a/lib/room.rb b/lib/room.rb index 94eab41ea..e6aee412a 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -7,7 +7,5 @@ def initialize(number) @id = number @reservations = [] end - - end end diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 52bd6ec48..deb3de48e 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -2,15 +2,19 @@ require 'pry' describe "ReservationsManager" do + before do + @hotel_ada = Hotel::ReservationsManager.new(20) + end describe "Initialize ReservationsManager" do it "is an instance of Hotel::ReservationsManager" do - hotel_ada = Hotel::ReservationsManager.new(20) - expect(hotel_ada).must_be_instance_of Hotel::ReservationsManager - expect(hotel_ada.rooms.count).must_equal 20 - expect(hotel_ada.rooms[0]).must_be_instance_of Hotel::Room - expect(hotel_ada.rooms).must_be_kind_of Array + expect(@hotel_ada).must_be_instance_of Hotel::ReservationsManager + expect(@hotel_ada.rooms.count).must_equal 20 + expect(@hotel_ada.rooms[0]).must_be_instance_of Hotel::Room + expect(@hotel_ada.rooms).must_be_kind_of Array end end + + # describe "List all rooms " end From 020026a7d80740d1e3f23a8e79e3a56513a44eac Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Wed, 5 Sep 2018 14:09:06 -0700 Subject: [PATCH 05/41] spike - built reservation manager and room classes --- lib/reservations_manager.rb | 6 ++++-- lib/room.rb | 10 +++++++++- spec/reservations_manager_spec.rb | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 80777ede7..21dccd481 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -4,7 +4,7 @@ #reservations manager module Hotel class ReservationsManager - attr_reader :rooms + attr_reader :rooms, :reservations def initialize(number_of_rooms) @rooms = [] (1..number_of_rooms).each do |number| @@ -13,6 +13,8 @@ def initialize(number_of_rooms) @reservations =[] end - + def reserve_room(start_date, end_date) + #create instance of reservation + #find available room, assign room to reservation id end end diff --git a/lib/room.rb b/lib/room.rb index e6aee412a..01eda86e3 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -2,10 +2,18 @@ module Hotel class Room - attr_reader + attr_reader :id, :reservations, :dates_booked def initialize(number) @id = number @reservations = [] + @dates_booked = [] end + + def find_available_room(start_date,end_date) + end + + def is_available(start_date,end_date) + end + end end diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index deb3de48e..32edd00cb 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -1,5 +1,6 @@ require_relative 'spec_helper' require 'pry' +require 'date' describe "ReservationsManager" do before do @@ -13,6 +14,8 @@ expect(@hotel_ada.rooms).must_be_kind_of Array end end + it "can reserve a room for a given date range" do + expect(@hotel_ada.reserve_room).must_be_instance_of Hotel::Reservation From 16b4e35f7a33195016155054f7b9a343ca84a51b Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Thu, 6 Sep 2018 11:43:07 -0700 Subject: [PATCH 06/41] updated spec_helper.rb --- lib/DateRange.rb | 14 ++++++++++++++ lib/reservations.rb | 25 +++++++++++++++++++++++++ lib/reservations_manager.rb | 12 ++++++++++-- lib/room.rb | 4 +++- spec/reservations_manager_spec.rb | 3 ++- spec/spec_helper.rb | 1 + 6 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 lib/DateRange.rb create mode 100644 lib/reservations.rb diff --git a/lib/DateRange.rb b/lib/DateRange.rb new file mode 100644 index 000000000..7412137ec --- /dev/null +++ b/lib/DateRange.rb @@ -0,0 +1,14 @@ +# module Hotel +# class DateRange +# def initialize(check_in, check_out) +# @check_in = Date.parse(check_in) +# @check_out = Date.parse(check_out) +# end +# +# def overlap +# end +# +# def include +# end +# +# def number_of_nights diff --git a/lib/reservations.rb b/lib/reservations.rb new file mode 100644 index 000000000..00951f241 --- /dev/null +++ b/lib/reservations.rb @@ -0,0 +1,25 @@ +COST_OF_ROOM = 200 + +module Hotel + class Reservation + + def initialize(number, check_in, check_out) + @id = number + @check_in = Date.parse(check_in) + @check_out = Date.parse(check_out) + @nights = check_out - check_in + @rooms = []#instance of a room + @total_cost = 0 + end + + + + def assign_room_to_reservation + end + + def calculate_reservation_cost(rooms) + total_cost = rooms.length * nights * COST_OF_ROOM + return total_cost + end + end + end diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 21dccd481..686fd39a6 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -1,9 +1,10 @@ require 'pry' require_relative 'room' +require_relative 'reservations' #reservations manager module Hotel - class ReservationsManager + class ReservationManager attr_reader :rooms, :reservations def initialize(number_of_rooms) @rooms = [] @@ -13,8 +14,15 @@ def initialize(number_of_rooms) @reservations =[] end - def reserve_room(start_date, end_date) + def reserve_room(check_in, check_out) + number = @reservations.length + +1 + @rooms.is_available(check_in, check_out) + new_reservation = Reservation.new(number, check_in, check_out) #create instance of reservation #find available room, assign room to reservation id + #ask room - do you have availability + end + + def end end diff --git a/lib/room.rb b/lib/room.rb index 01eda86e3..628de6b65 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -6,13 +6,15 @@ class Room def initialize(number) @id = number @reservations = [] - @dates_booked = [] + #@dates_booked = [] end def find_available_room(start_date,end_date) end def is_available(start_date,end_date) + @reservations.conflict?(check_in, check_out) + #reject - rooms that are nto available for dates end end diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 32edd00cb..59c427aa6 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -15,7 +15,8 @@ end end it "can reserve a room for a given date range" do - expect(@hotel_ada.reserve_room).must_be_instance_of Hotel::Reservation + expect(@hotel_ada.reserve_room(start_date, end_date)).must_be_instance_of Hotel::Reservation + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 035ac265a..3f86ce686 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,3 +11,4 @@ # Require_relative your lib files here! require_relative '../lib/reservations_manager.rb' require_relative '../lib/room.rb' +require_relative '../lib/reservations.rb' From 8314ff05a34dacf676978151c5dbeb7dfd05f970 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Fri, 7 Sep 2018 08:00:39 -0700 Subject: [PATCH 07/41] final design --- lib/reservations.rb | 8 ++++---- lib/reservations_manager.rb | 29 +++++++++++++++++++++++++++-- lib/room.rb | 13 +++---------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 00951f241..aad20eeaf 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -12,10 +12,10 @@ def initialize(number, check_in, check_out) @total_cost = 0 end - - - def assign_room_to_reservation - end + def find_reservation(date) + #loop through reser ations and match by date + return reservations #array + end def calculate_reservation_cost(rooms) total_cost = rooms.length * nights * COST_OF_ROOM diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 686fd39a6..20c0d11e3 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -14,10 +14,35 @@ def initialize(number_of_rooms) @reservations =[] end + def available_rooms(check_in, check_out) + available_rooms = @reservations.reject {rooms != date_range} + #loop through Reservations @match dates on the reservations#reject dates that match + return available_rooms #array + + def find_room(id) + @roooms.find(id) + return #instance of room + end + + def booked_rooms(date) + booked_rooms = @reservations.select {rooms == date_range} + return booked_rooms #array + def reserve_room(check_in, check_out) - number = @reservations.length + +1 - @rooms.is_available(check_in, check_out) + number = @reservations.length + 1 new_reservation = Reservation.new(number, check_in, check_out) + assigned_room = available_rooms(check_in, check_out).first + new_reservation.rooms << assigned_room + find_room(assigned_room.id).reservations << new_reservation + end + + def rooms.all + return @rooms + end + + def reservations.all + return @reservations + end #create instance of reservation #find available room, assign room to reservation id #ask room - do you have availability diff --git a/lib/room.rb b/lib/room.rb index 628de6b65..b5f06818c 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -2,19 +2,12 @@ module Hotel class Room - attr_reader :id, :reservations, :dates_booked + attr_reader :id + attr_accessor :reservations + def initialize(number) @id = number @reservations = [] - #@dates_booked = [] - end - - def find_available_room(start_date,end_date) - end - - def is_available(start_date,end_date) - @reservations.conflict?(check_in, check_out) - #reject - rooms that are nto available for dates end end From 6f963c63b2bb481646d1c65d84f46723f9d41bed Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Fri, 7 Sep 2018 10:57:16 -0700 Subject: [PATCH 08/41] keyword arguments --- lib/reservations.rb | 2 +- lib/room.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index aad20eeaf..e0a1d590a 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -3,7 +3,7 @@ module Hotel class Reservation - def initialize(number, check_in, check_out) + def initialize(number: , check_in:, check_out:) @id = number @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) diff --git a/lib/room.rb b/lib/room.rb index b5f06818c..2eddbe0d0 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -10,5 +10,7 @@ def initialize(number) @reservations = [] end + def is_available(check_in: check_in, check_out: check_out) + self.reservations.include? end end From d0a65450c7b231058684ab4fce84174f642e29c6 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Sun, 9 Sep 2018 22:55:47 -0700 Subject: [PATCH 09/41] removed is_available method, save for wave 2 --- lib/reservations.rb | 12 +++++---- lib/reservations_manager.rb | 42 +++++++++++++++---------------- lib/room.rb | 11 ++++++-- spec/reservations_manager_spec.rb | 33 +++++++++++++++++------- spec/reservations_spec.rb | 2 ++ spec/room_spec.rb | 5 ++-- 6 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 spec/reservations_spec.rb diff --git a/lib/reservations.rb b/lib/reservations.rb index e0a1d590a..6bff9df29 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -1,12 +1,14 @@ COST_OF_ROOM = 200 +require 'Date' module Hotel class Reservation - def initialize(number: , check_in:, check_out:) + def initialize(number, check_in: check_in, check_out: check_out) @id = number @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) + @date_range = (check_in..check_out) @nights = check_out - check_in @rooms = []#instance of a room @total_cost = 0 @@ -17,9 +19,9 @@ def find_reservation(date) return reservations #array end - def calculate_reservation_cost(rooms) - total_cost = rooms.length * nights * COST_OF_ROOM - return total_cost - end + def calculate_reservation_cost(rooms) + total_cost = rooms.length * nights * COST_OF_ROOM + return total_cost end end +end diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 20c0d11e3..bc28a119f 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -14,40 +14,38 @@ def initialize(number_of_rooms) @reservations =[] end - def available_rooms(check_in, check_out) - available_rooms = @reservations.reject {rooms != date_range} - #loop through Reservations @match dates on the reservations#reject dates that match - return available_rooms #array - - def find_room(id) - @roooms.find(id) - return #instance of room - end - - def booked_rooms(date) - booked_rooms = @reservations.select {rooms == date_range} - return booked_rooms #array + # def available_rooms(check_in, check_out) + # available_rooms = @reservations.reject {rooms != date_range} + # #loop through Reservations @match dates on the reservations#reject dates that match + # return available_rooms #array + + # def find_room(id) + # @roooms.find(id) + # return #instance of room + # end + # + # def booked_rooms(date) + # booked_rooms = @reservations.select {rooms == date_range} + # return booked_rooms #array def reserve_room(check_in, check_out) - number = @reservations.length + 1 - new_reservation = Reservation.new(number, check_in, check_out) - assigned_room = available_rooms(check_in, check_out).first + #number = @reservations.length + 1 + new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) + # assigned_room = available_rooms(check_in, check_out).first new_reservation.rooms << assigned_room find_room(assigned_room.id).reservations << new_reservation + return new_reservation end - def rooms.all - return @rooms - end - def reservations.all + + def @reservations.all return @reservations end #create instance of reservation #find available room, assign room to reservation id #ask room - do you have availability - end - def + end end diff --git a/lib/room.rb b/lib/room.rb index 2eddbe0d0..5f4585286 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,4 +1,5 @@ require 'pry' +require 'Date' module Hotel class Room @@ -8,9 +9,15 @@ class Room def initialize(number) @id = number @reservations = [] + #define room as physical space end - def is_available(check_in: check_in, check_out: check_out) - self.reservations.include? + #wave 2 def is_available(check_in:, check_out:) + # date_range = Date.parse(check_in)..Date.parse(check_out) + # #loop through room reservations, reject rooms with reservations that conflict with + # #requested date range + # self.reservations.reject {@reservations} date_range + # # end + # end end end diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 59c427aa6..01be2e31a 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -1,24 +1,39 @@ require_relative 'spec_helper' require 'pry' -require 'date' +require 'Date' -describe "ReservationsManager" do +describe "ReservationManager" do before do - @hotel_ada = Hotel::ReservationsManager.new(20) + @hotel_ada = Hotel::ReservationManager.new(20) end + describe "Initialize ReservationsManager" do it "is an instance of Hotel::ReservationsManager" do - expect(@hotel_ada).must_be_instance_of Hotel::ReservationsManager + expect(@hotel_ada).must_be_instance_of Hotel::ReservationManager + expect(@hotel_ada.reservations).must_be_kind_of Array + end + end + + describe "Access all rooms" do + it "returns a list of all rooms" do expect(@hotel_ada.rooms.count).must_equal 20 - expect(@hotel_ada.rooms[0]).must_be_instance_of Hotel::Room expect(@hotel_ada.rooms).must_be_kind_of Array + expect(@hotel_ada.rooms[0]).must_be_instance_of Hotel::Room end - end - it "can reserve a room for a given date range" do - expect(@hotel_ada.reserve_room(start_date, end_date)).must_be_instance_of Hotel::Reservation + # wave 2 it "returns a list of all available rooms" do + # expect(@hotel_ada.available_rooms(check_in:"08.23.2018", check_out:"08.25.2018")).must_be_kind_of Array + # expect(@hotel_ada.available_rooms(check_in:"08.23.2018", check_out:"08.25.2018")[0]).must_be_kind_of Hotel::Room + # #expect(@hotel_ada.available_rooms("08.23.2018", "08.25.2018")[0].id).must_equal #rooom ID + # end + end + describe "reserve_room ReservationManager" do + it "can reserve a room for a given date range" do + expect(@hotel_ada.reserve_room(check_in:"08-23-2018", check_out:"08-25-2018")).must_be_instance_of Hotel::Reservation + end + end +end # describe "List all rooms " -end diff --git a/spec/reservations_spec.rb b/spec/reservations_spec.rb new file mode 100644 index 000000000..1a8982905 --- /dev/null +++ b/spec/reservations_spec.rb @@ -0,0 +1,2 @@ +require_relative 'spec_helper' +require 'pry' diff --git a/spec/room_spec.rb b/spec/room_spec.rb index 34b6aca79..ae6b8346d 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -6,7 +6,8 @@ it "is an instance of Hotel::Room" do hotel_room = Hotel::Room.new(1) - expect(hotel_room).must_be_kind_of Hotel::Room + expect(hotel_room).must_be_instance_of Hotel::Room + expect(hotel_room.reservations).must_be_kind_of Array end end @@ -17,6 +18,6 @@ # expect(hotel_ada.rooms.count).must_equal 20 # expect(hotel_ada.rooms[0]).must_be_instance_of Hotel::Room # expect(hotel_ada.rooms).must_be_kind_of Array - + end From 5f01796fd02893dd573d07e8478d941afb5825d3 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Sun, 9 Sep 2018 23:19:13 -0700 Subject: [PATCH 10/41] passed all tests, added reserve_room method --- lib/reservations.rb | 3 +-- lib/reservations_manager.rb | 9 ++++----- spec/reservations_manager_spec.rb | 2 +- spec/room_spec.rb | 15 +++++---------- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 6bff9df29..29f447562 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -8,8 +8,7 @@ def initialize(number, check_in: check_in, check_out: check_out) @id = number @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) - @date_range = (check_in..check_out) - @nights = check_out - check_in + #@date_range = (@check_in..@check_out) @rooms = []#instance of a room @total_cost = 0 end diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index bc28a119f..9654ad49c 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -1,4 +1,5 @@ require 'pry' +require 'Date' require_relative 'room' require_relative 'reservations' @@ -7,11 +8,11 @@ module Hotel class ReservationManager attr_reader :rooms, :reservations def initialize(number_of_rooms) + @reservations = [] @rooms = [] (1..number_of_rooms).each do |number| @rooms << Room.new(number) end - @reservations =[] end # def available_rooms(check_in, check_out) @@ -29,11 +30,9 @@ def initialize(number_of_rooms) # return booked_rooms #array def reserve_room(check_in, check_out) - #number = @reservations.length + 1 new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) - # assigned_room = available_rooms(check_in, check_out).first - new_reservation.rooms << assigned_room - find_room(assigned_room.id).reservations << new_reservation + #new_reservation.rooms << assigned_room + #find_room(assigned_room.id).reservations << new_reservation return new_reservation end diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 01be2e31a..5b1d96686 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -31,7 +31,7 @@ describe "reserve_room ReservationManager" do it "can reserve a room for a given date range" do - expect(@hotel_ada.reserve_room(check_in:"08-23-2018", check_out:"08-25-2018")).must_be_instance_of Hotel::Reservation + expect(@hotel_ada.reserve_room('2018-08-23', '2018-08-25')).must_be_instance_of Hotel::Reservation end end end diff --git a/spec/room_spec.rb b/spec/room_spec.rb index ae6b8346d..eb2958f52 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -10,14 +10,9 @@ expect(hotel_room.reservations).must_be_kind_of Array end end - - # describe "create_rooms" do - # it "creates specified number of hotel rooms" do - # hotel_ada = Hotel::Room.create_rooms(20) - # expect(hotel_ada).must_be_instance_of Hotel::Room - # expect(hotel_ada.rooms.count).must_equal 20 - # expect(hotel_ada.rooms[0]).must_be_instance_of Hotel::Room - # expect(hotel_ada.rooms).must_be_kind_of Array - - + # wave 2 describe "is_available method" do + # it "checks to see which rooms are available for a given date range" do + # expect(hotel_room.is_available(check_in: '08-23-2018', check_out: '08-25-2018')).must_be_kind_of Array + # + # end end From 914e35a112eee8bf5ab7d30d96ef83879f980029 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Sun, 9 Sep 2018 23:26:15 -0700 Subject: [PATCH 11/41] added test to reservation mgr about reserving room, added instance of room to new reservation --- lib/reservations.rb | 1 + lib/reservations_manager.rb | 2 +- spec/reservations_manager_spec.rb | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 29f447562..2065798f0 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -3,6 +3,7 @@ module Hotel class Reservation + attr_reader :id, :check_in, :check_out, :rooms, :total_cost def initialize(number, check_in: check_in, check_out: check_out) @id = number diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 9654ad49c..c4a606800 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -31,7 +31,7 @@ def initialize(number_of_rooms) def reserve_room(check_in, check_out) new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) - #new_reservation.rooms << assigned_room + new_reservation.rooms << @rooms[0] #find_room(assigned_room.id).reservations << new_reservation return new_reservation end diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 5b1d96686..e24d90fc7 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -30,9 +30,22 @@ describe "reserve_room ReservationManager" do + before do + @new_reservation = @hotel_ada.reserve_room('2018-08-23', '2018-08-25') + end it "can reserve a room for a given date range" do - expect(@hotel_ada.reserve_room('2018-08-23', '2018-08-25')).must_be_instance_of Hotel::Reservation + expect(@new_reservation).must_be_instance_of Hotel::Reservation + expect(@new_reservation.id).must_equal 1 + expect(@new_reservation.check_in).must_be_instance_of Date + + end + + it "adds an instance of a room to the reservation" do + expect(@hotel_ada.reserve_room('2018-08-23', '2018-08-25').rooms).must_be_kind_of Array + expect(@hotel_ada.reserve_room('2018-08-23', '2018-08-25').rooms[0]).must_be_instance_of Hotel::Room end + + end end From f7791af5f4a47c732ccd4745c0a01d744497e74b Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Sun, 9 Sep 2018 23:32:09 -0700 Subject: [PATCH 12/41] Added test to check room id of reservation --- lib/reservations_manager.rb | 1 + spec/reservations_manager_spec.rb | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index c4a606800..5d2da6ecf 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -32,6 +32,7 @@ def initialize(number_of_rooms) def reserve_room(check_in, check_out) new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) new_reservation.rooms << @rooms[0] + #find_room(assigned_room.id).reservations << new_reservation return new_reservation end diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index e24d90fc7..88c4fc520 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -37,14 +37,19 @@ expect(@new_reservation).must_be_instance_of Hotel::Reservation expect(@new_reservation.id).must_equal 1 expect(@new_reservation.check_in).must_be_instance_of Date - end it "adds an instance of a room to the reservation" do - expect(@hotel_ada.reserve_room('2018-08-23', '2018-08-25').rooms).must_be_kind_of Array - expect(@hotel_ada.reserve_room('2018-08-23', '2018-08-25').rooms[0]).must_be_instance_of Hotel::Room + expect(@new_reservation.rooms).must_be_kind_of Array + expect(@new_reservation.rooms[0]).must_be_instance_of Hotel::Room end + it "adds the reservation to the instance of room" do + expect(@new_reservation.rooms[0].id).must_equal 1 + end + + + end end From 9fb7b66bb0ce5255d8f8f82a9603e4c3ac000c36 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Sun, 9 Sep 2018 23:41:42 -0700 Subject: [PATCH 13/41] Added find_room method and added instance of reservation to room object --- lib/reservations_manager.rb | 30 +++++++++++++++++------------- lib/room.rb | 6 ++++++ spec/reservations_manager_spec.rb | 3 +++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 5d2da6ecf..faa571cfa 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -20,28 +20,32 @@ def initialize(number_of_rooms) # #loop through Reservations @match dates on the reservations#reject dates that match # return available_rooms #array - # def find_room(id) - # @roooms.find(id) - # return #instance of room + def find_room(id) + @rooms.each do |room| + if room.id == id + return room + end + end + end # end # # def booked_rooms(date) # booked_rooms = @reservations.select {rooms == date_range} # return booked_rooms #array - def reserve_room(check_in, check_out) - new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) - new_reservation.rooms << @rooms[0] - - #find_room(assigned_room.id).reservations << new_reservation - return new_reservation - end + def reserve_room(check_in, check_out) + new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) + assigned_room = @rooms[0] + new_reservation.rooms << assigned_room + find_room(assigned_room.id).reservations << new_reservation + return new_reservation + end - def @reservations.all - return @reservations - end + def @reservations.all + return @reservations + end #create instance of reservation #find available room, assign room to reservation id #ask room - do you have availability diff --git a/lib/room.rb b/lib/room.rb index 5f4585286..f55ce4a4b 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -12,6 +12,12 @@ def initialize(number) #define room as physical space end + # def self.find_room(id) + # if room.id == id + # return room + # end + # end + #wave 2 def is_available(check_in:, check_out:) # date_range = Date.parse(check_in)..Date.parse(check_out) # #loop through room reservations, reject rooms with reservations that conflict with diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 88c4fc520..38c2ad9e8 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -46,6 +46,9 @@ it "adds the reservation to the instance of room" do expect(@new_reservation.rooms[0].id).must_equal 1 + expect(@new_reservation.rooms[0].reservations).must_be_kind_of Array + expect(@new_reservation.rooms[0].reservations[0]).must_be_instance_of Hotel:: Reservation + expect(@new_reservation.rooms[0].reservations[0].id).must_equal 1 end From 891c3c4bf2ca02b95db6f86a3206683b39863978 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Sun, 9 Sep 2018 23:50:51 -0700 Subject: [PATCH 14/41] added booked_reservations method and tests --- lib/reservations.rb | 2 +- lib/reservations_manager.rb | 19 ++++++++++--------- spec/reservations_manager_spec.rb | 9 ++++++--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 2065798f0..b7dafff36 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -9,7 +9,7 @@ def initialize(number, check_in: check_in, check_out: check_out) @id = number @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) - #@date_range = (@check_in..@check_out) + @date_range = (@check_in..@check_out) @rooms = []#instance of a room @total_cost = 0 end diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index faa571cfa..7572bdb11 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -6,7 +6,9 @@ #reservations manager module Hotel class ReservationManager + attr_reader :rooms, :reservations + def initialize(number_of_rooms) @reservations = [] @rooms = [] @@ -15,11 +17,6 @@ def initialize(number_of_rooms) end end - # def available_rooms(check_in, check_out) - # available_rooms = @reservations.reject {rooms != date_range} - # #loop through Reservations @match dates on the reservations#reject dates that match - # return available_rooms #array - def find_room(id) @rooms.each do |room| if room.id == id @@ -27,10 +24,10 @@ def find_room(id) end end end - # end - # - # def booked_rooms(date) - # booked_rooms = @reservations.select {rooms == date_range} + + def booked_reservations(date) + return reservations = @reservations.select {|reservation| reservations.date_range.include? date} + end # return booked_rooms #array def reserve_room(check_in, check_out) @@ -42,6 +39,10 @@ def reserve_room(check_in, check_out) end + # def available_rooms(check_in, check_out) + # available_rooms = @reservations.reject {rooms != date_range} + # #loop through Reservations @match dates on the reservations#reject dates that match + # return available_rooms #array def @reservations.all return @reservations diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 38c2ad9e8..54d4cd165 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -50,10 +50,13 @@ expect(@new_reservation.rooms[0].reservations[0]).must_be_instance_of Hotel:: Reservation expect(@new_reservation.rooms[0].reservations[0].id).must_equal 1 end + end - - - + describe "it can list all reservations for a given date" do + it "returns a list of rooms for given date" do + expect(@hotel_ada.booked_reservations("2018-09-09")).must_be_kind_of Array + expect(@hotel_ada.booked_reservations("2018-09-09")[0]).must_be_instance_of Hotel::Reservation + end end end From f3c744c01dcb7e1fe46be72f4c34d8a3366e5d88 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Mon, 10 Sep 2018 18:14:23 -0700 Subject: [PATCH 15/41] add find_reservatin method to reservation clas --- lib/reservations.rb | 16 +++++++++++----- lib/reservations_manager.rb | 12 ++++++------ lib/room.rb | 2 +- spec/reservations_manager_spec.rb | 2 +- spec/spec_helper.rb | 1 + 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index b7dafff36..2d09f894e 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -1,22 +1,28 @@ COST_OF_ROOM = 200 -require 'Date' +# require 'Date' module Hotel class Reservation attr_reader :id, :check_in, :check_out, :rooms, :total_cost - def initialize(number, check_in: check_in, check_out: check_out) + def initialize(number, check_in: , check_out: ) @id = number @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) @date_range = (@check_in..@check_out) - @rooms = []#instance of a room + @rooms = []#instance of a room # reconsider- might not need but maybe @total_cost = 0 end def find_reservation(date) - #loop through reser ations and match by date - return reservations #array + reservation.date_range.include? date#loop through reser ations and match by date + return reservation + end + + #check overlap + #reservations_manager.reservations + def do_conflict?(dates) + reservation.date_range.include? date end def calculate_reservation_cost(rooms) diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 7572bdb11..0e595568c 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -1,5 +1,5 @@ require 'pry' -require 'Date' +# require 'Date' require_relative 'room' require_relative 'reservations' @@ -26,13 +26,13 @@ def find_room(id) end def booked_reservations(date) - return reservations = @reservations.select {|reservation| reservations.date_range.include? date} + return reservations = @reservations.select {|reservation| reservations.find_reservation == true} end # return booked_rooms #array def reserve_room(check_in, check_out) new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) - assigned_room = @rooms[0] + assigned_room = @rooms[0]#available_rooms new_reservation.rooms << assigned_room find_room(assigned_room.id).reservations << new_reservation return new_reservation @@ -44,9 +44,9 @@ def reserve_room(check_in, check_out) # #loop through Reservations @match dates on the reservations#reject dates that match # return available_rooms #array - def @reservations.all - return @reservations - end + # def @reservations.all + # return @reservations + # end #create instance of reservation #find available room, assign room to reservation id #ask room - do you have availability diff --git a/lib/room.rb b/lib/room.rb index f55ce4a4b..fcb7c3588 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,5 +1,5 @@ require 'pry' -require 'Date' +# require 'Date' module Hotel class Room diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 54d4cd165..cc21647ac 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -1,6 +1,6 @@ require_relative 'spec_helper' require 'pry' -require 'Date' +# require 'Date' describe "ReservationManager" do before do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3f86ce686..9431529e5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ require 'minitest/autorun' require 'minitest/reporters' + # Add simplecov Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 92f91e31511250b7952596993b4772ed2fe76f21 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 11 Sep 2018 17:53:31 -0700 Subject: [PATCH 16/41] added find_reservation --- lib/reservations.rb | 10 +++++----- lib/reservations_manager.rb | 2 +- lib/room.rb | 2 +- spec/reservations_manager_spec.rb | 14 +++++++++++++- spec/reservations_spec.rb | 26 ++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 2d09f894e..6d44908d1 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -3,23 +3,23 @@ module Hotel class Reservation - attr_reader :id, :check_in, :check_out, :rooms, :total_cost + attr_reader :id, :check_in, :check_out, :rooms, :total_cost, :date_range def initialize(number, check_in: , check_out: ) @id = number @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) - @date_range = (@check_in..@check_out) + @date_range = (@check_in...@check_out) @rooms = []#instance of a room # reconsider- might not need but maybe @total_cost = 0 end def find_reservation(date) - reservation.date_range.include? date#loop through reser ations and match by date - return reservation + date = Date.parse(date) + return self.date_range.include? date end - #check overlap + #check overlap #reservations_manager.reservations def do_conflict?(dates) reservation.date_range.include? date diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 0e595568c..6aac8ab39 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -26,7 +26,7 @@ def find_room(id) end def booked_reservations(date) - return reservations = @reservations.select {|reservation| reservations.find_reservation == true} + return reservations = @reservations.select {|reservation| reservation.find_reservation == true} end # return booked_rooms #array diff --git a/lib/room.rb b/lib/room.rb index fcb7c3588..cf4a3e14c 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -11,7 +11,7 @@ def initialize(number) @reservations = [] #define room as physical space end - + #create helper methods that return boolean values - in reservmgr - create loop methods that take helper method booleans and creates an array # def self.find_room(id) # if room.id == id # return room diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index cc21647ac..9df672bae 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -31,7 +31,19 @@ describe "reserve_room ReservationManager" do before do - @new_reservation = @hotel_ada.reserve_room('2018-08-23', '2018-08-25') + @dateA = '2018-08-23' + @dateB = '2018-08-25' + @dateC = '2018-08-09' + @dateD = '2018-08-27' + @dateE = '2018-08-15' + @dateF = '2018-08-20' + + @new_reservation1 = @hotel_ada.reserve_room('2018-08-23', '2018-08-25') + @new_reservation2 = @hotel_ada.reserve_room('2018-08-19', '2018-08-22') + @new_reservation3 = @hotel_ada.reserve_room('2018-08-09', '2018-08-15') + @new_reservation4 = @hotel_ada.reserve_room('2018-08-23', '2018-08-27') + @new_reservation5 = @hotel_ada.reserve_room('2018-08-20', '2018-08-25') + end it "can reserve a room for a given date range" do expect(@new_reservation).must_be_instance_of Hotel::Reservation diff --git a/spec/reservations_spec.rb b/spec/reservations_spec.rb index 1a8982905..7b31e2062 100644 --- a/spec/reservations_spec.rb +++ b/spec/reservations_spec.rb @@ -1,2 +1,28 @@ require_relative 'spec_helper' require 'pry' + +describe "Reservation" do + before do + @hotel_ada = Hotel::ReservationManager.new(20) + @new_reservation = @hotel_ada.reserve_room("2018-08-23", "2018-08-25") + end + + describe "Initializes an instance of reservation and its instance methods" do + before do + @test_reservation = Hotel::Reservation.new(1, check_in: "2018-09-18", check_out: "2018-09-20") + end + + it "creates an instance of Reservation" do + expect(@test_reservation).must_be_instance_of Hotel::Reservation + expect(@test_reservation.rooms).must_be_kind_of Array + expect(@test_reservation.check_in).must_be_instance_of Date + expect(@test_reservation.check_in.day).must_equal 18 + expect(@test_reservation.date_range.count).must_equal 2 + end + + it "checks to see if there are any reservations for a given date" do +#binding.pry + expect(@test_reservation.find_reservation("2018-09-19")).must_equal true + end + end +end From b58469a02322d5c35b86366579e10a7ef88c738a Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 11 Sep 2018 18:10:21 -0700 Subject: [PATCH 17/41] passed all tests --- lib/reservations.rb | 2 +- lib/reservations_manager.rb | 1 + spec/reservations_manager_spec.rb | 28 +++++++++++++++------------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 6d44908d1..76e63f9e2 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -3,7 +3,7 @@ module Hotel class Reservation - attr_reader :id, :check_in, :check_out, :rooms, :total_cost, :date_range + attr_reader :id, :check_in, :check_out, :rooms, :total_cost, :date_range, :rooms def initialize(number, check_in: , check_out: ) @id = number diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 6aac8ab39..81180654b 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -29,6 +29,7 @@ def booked_reservations(date) return reservations = @reservations.select {|reservation| reservation.find_reservation == true} end # return booked_rooms #array + #use same find_reservation method for rooms select for available, reject for booked def reserve_room(check_in, check_out) new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 9df672bae..018f8330d 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -31,18 +31,19 @@ describe "reserve_room ReservationManager" do before do - @dateA = '2018-08-23' - @dateB = '2018-08-25' - @dateC = '2018-08-09' - @dateD = '2018-08-27' - @dateE = '2018-08-15' - @dateF = '2018-08-20' + @dateA = '2018-08-09' + @dateB = '2018-08-15' + @dateC = '2018-08-20' + @dateD = '2018-08-23' + @dateE = '2018-08-25' + @dateF = '2018-08-27' + @test_date = '2018-08-20' - @new_reservation1 = @hotel_ada.reserve_room('2018-08-23', '2018-08-25') - @new_reservation2 = @hotel_ada.reserve_room('2018-08-19', '2018-08-22') - @new_reservation3 = @hotel_ada.reserve_room('2018-08-09', '2018-08-15') - @new_reservation4 = @hotel_ada.reserve_room('2018-08-23', '2018-08-27') - @new_reservation5 = @hotel_ada.reserve_room('2018-08-20', '2018-08-25') + @new_reservation1 = @hotel_ada.reserve_room( @dateA, @dateC) + @new_reservation2 = @hotel_ada.reserve_room(@dateB, @dateD) + @new_reservation3 = @hotel_ada.reserve_room(@dateE, @dateF) + @new_reservation4 = @hotel_ada.reserve_room(@dateA, @dateD) + @new_reservation5 = @hotel_ada.reserve_room(@dateC, @dateD) end it "can reserve a room for a given date range" do @@ -66,8 +67,9 @@ describe "it can list all reservations for a given date" do it "returns a list of rooms for given date" do - expect(@hotel_ada.booked_reservations("2018-09-09")).must_be_kind_of Array - expect(@hotel_ada.booked_reservations("2018-09-09")[0]).must_be_instance_of Hotel::Reservation + expect(@hotel_ada.booked_reservations(@test_date)).must_be_kind_of Array + expect(@hotel_ada.booked_reservations(@test_date)[0]).must_be_instance_of Hotel::Reservation + expect(@hotel_ada.booked_reservations(@test_date).length).must_equal 3 end end end From e57bce735406a9838ea8c77872e67ac00340a811 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 11 Sep 2018 18:59:34 -0700 Subject: [PATCH 18/41] fixed booked reservations method --- lib/reservations.rb | 4 +-- lib/reservations_manager.rb | 3 +- spec/reservations_manager_spec.rb | 52 ++++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 76e63f9e2..eb8d03f14 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -3,9 +3,9 @@ module Hotel class Reservation - attr_reader :id, :check_in, :check_out, :rooms, :total_cost, :date_range, :rooms + attr_reader :id, :check_in, :check_out, :rooms, :total_cost, :date_range - def initialize(number, check_in: , check_out: ) + def initialize(number, check_in:, check_out:) @id = number @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 81180654b..d9d4e885d 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -26,7 +26,7 @@ def find_room(id) end def booked_reservations(date) - return reservations = @reservations.select {|reservation| reservation.find_reservation == true} + return reservations = @reservations.select {|reservation| reservation.find_reservation(date) == true} end # return booked_rooms #array #use same find_reservation method for rooms select for available, reject for booked @@ -36,6 +36,7 @@ def reserve_room(check_in, check_out) assigned_room = @rooms[0]#available_rooms new_reservation.rooms << assigned_room find_room(assigned_room.id).reservations << new_reservation + @reservations << new_reservation return new_reservation end diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 018f8330d..722f4211d 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -31,43 +31,71 @@ describe "reserve_room ReservationManager" do before do + @hotel_ada = Hotel::ReservationManager.new(20) @dateA = '2018-08-09' @dateB = '2018-08-15' @dateC = '2018-08-20' @dateD = '2018-08-23' @dateE = '2018-08-25' @dateF = '2018-08-27' - @test_date = '2018-08-20' + @test_date ='2018-08-20' - @new_reservation1 = @hotel_ada.reserve_room( @dateA, @dateC) + @new_reservation1 = @hotel_ada.reserve_room(@dateA, @dateC) @new_reservation2 = @hotel_ada.reserve_room(@dateB, @dateD) @new_reservation3 = @hotel_ada.reserve_room(@dateE, @dateF) @new_reservation4 = @hotel_ada.reserve_room(@dateA, @dateD) @new_reservation5 = @hotel_ada.reserve_room(@dateC, @dateD) + end + it "can reserve a room for a given date range" do - expect(@new_reservation).must_be_instance_of Hotel::Reservation - expect(@new_reservation.id).must_equal 1 - expect(@new_reservation.check_in).must_be_instance_of Date + expect(@new_reservation1).must_be_instance_of Hotel::Reservation + expect(@new_reservation1.id).must_equal 1 + expect(@new_reservation1.check_in).must_be_instance_of Date end it "adds an instance of a room to the reservation" do - expect(@new_reservation.rooms).must_be_kind_of Array - expect(@new_reservation.rooms[0]).must_be_instance_of Hotel::Room + expect(@new_reservation1.rooms).must_be_kind_of Array + expect(@new_reservation1.rooms[0]).must_be_instance_of Hotel::Room end it "adds the reservation to the instance of room" do - expect(@new_reservation.rooms[0].id).must_equal 1 - expect(@new_reservation.rooms[0].reservations).must_be_kind_of Array - expect(@new_reservation.rooms[0].reservations[0]).must_be_instance_of Hotel:: Reservation - expect(@new_reservation.rooms[0].reservations[0].id).must_equal 1 + expect(@new_reservation1.rooms[0].id).must_equal 1 + expect(@new_reservation1.rooms[0].reservations).must_be_kind_of Array + expect(@new_reservation1.rooms[0].reservations[0]).must_be_instance_of Hotel:: Reservation + expect(@new_reservation1.rooms[0].reservations[0].id).must_equal 1 end end describe "it can list all reservations for a given date" do + before do + @hotel_ada = Hotel::ReservationManager.new(20) + # @dateA = Date.parse('2018-08-09') + # @dateB = Date.parse('2018-08-15') + # @dateC = Date.parse('2018-08-20') + # @dateD = Date.parse('2018-08-23') + # @dateE = Date.parse('2018-08-25') + # @dateF = Date.parse('2018-08-27') + # @test_date = Date.parse('2018-08-20') + @dateA = '2018-08-09' + @dateB = '2018-08-15' + @dateC = '2018-08-20' + @dateD = '2018-08-23' + @dateE ='2018-08-25' + @dateF = '2018-08-27' + @test_date = '2018-08-20' + + @new_reservation1 = @hotel_ada.reserve_room(@dateA, @dateC) + @new_reservation2 = @hotel_ada.reserve_room(@dateB, @dateD) + @new_reservation3 = @hotel_ada.reserve_room(@dateE, @dateF) + @new_reservation4 = @hotel_ada.reserve_room(@dateA, @dateD) + @new_reservation5 = @hotel_ada.reserve_room(@dateC, @dateD) + + end it "returns a list of rooms for given date" do - expect(@hotel_ada.booked_reservations(@test_date)).must_be_kind_of Array + expect(@hotel_ada.booked_reservations(@test_date)).must_be_kind_of Array + #binding.pry expect(@hotel_ada.booked_reservations(@test_date)[0]).must_be_instance_of Hotel::Reservation expect(@hotel_ada.booked_reservations(@test_date).length).must_equal 3 end From 85afc9ad27b96cf58e0c951259ed9dbfd6eafa05 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 11 Sep 2018 20:02:26 -0700 Subject: [PATCH 19/41] added total cost method --- lib/reservations.rb | 15 +++++++++------ lib/reservations_manager.rb | 2 +- spec/reservations_manager_spec.rb | 18 +++++------------- spec/reservations_spec.rb | 15 ++++++++------- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index eb8d03f14..86669cb2c 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -1,17 +1,20 @@ -COST_OF_ROOM = 200 + # require 'Date' module Hotel + COST_OF_ROOM = 200 class Reservation attr_reader :id, :check_in, :check_out, :rooms, :total_cost, :date_range + attr_accessor :total_cost + def initialize(number, check_in:, check_out:) @id = number @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) @date_range = (@check_in...@check_out) @rooms = []#instance of a room # reconsider- might not need but maybe - @total_cost = 0 + @total_cost = @date_range.count * COST_OF_ROOM #wanted it to be @rooms.length * end def find_reservation(date) @@ -25,9 +28,9 @@ def do_conflict?(dates) reservation.date_range.include? date end - def calculate_reservation_cost(rooms) - total_cost = rooms.length * nights * COST_OF_ROOM - return total_cost - end + # def self.calculate_reservation_cost + # total_cost = @rooms.length * @date_range.count * COST_OF_ROOM + # return total_cost + # end end end diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index d9d4e885d..da6ef688c 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -34,7 +34,7 @@ def booked_reservations(date) def reserve_room(check_in, check_out) new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) assigned_room = @rooms[0]#available_rooms - new_reservation.rooms << assigned_room + new_reservation.rooms << assigned_room.id find_room(assigned_room.id).reservations << new_reservation @reservations << new_reservation return new_reservation diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 722f4211d..0d3214841 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -55,29 +55,21 @@ expect(@new_reservation1.check_in).must_be_instance_of Date end - it "adds an instance of a room to the reservation" do + it "adds room id to the reservation" do expect(@new_reservation1.rooms).must_be_kind_of Array - expect(@new_reservation1.rooms[0]).must_be_instance_of Hotel::Room + expect(@new_reservation1.rooms[0]).must_equal 1 end it "adds the reservation to the instance of room" do - expect(@new_reservation1.rooms[0].id).must_equal 1 - expect(@new_reservation1.rooms[0].reservations).must_be_kind_of Array - expect(@new_reservation1.rooms[0].reservations[0]).must_be_instance_of Hotel:: Reservation - expect(@new_reservation1.rooms[0].reservations[0].id).must_equal 1 + expect(@hotel_ada.rooms[0].reservations).must_be_kind_of Array + expect(@hotel_ada.rooms[0].reservations[0]).must_be_instance_of Hotel:: Reservation + expect(@hotel_ada.rooms[0].reservations[0].id).must_equal 1 end end describe "it can list all reservations for a given date" do before do @hotel_ada = Hotel::ReservationManager.new(20) - # @dateA = Date.parse('2018-08-09') - # @dateB = Date.parse('2018-08-15') - # @dateC = Date.parse('2018-08-20') - # @dateD = Date.parse('2018-08-23') - # @dateE = Date.parse('2018-08-25') - # @dateF = Date.parse('2018-08-27') - # @test_date = Date.parse('2018-08-20') @dateA = '2018-08-09' @dateB = '2018-08-15' @dateC = '2018-08-20' diff --git a/spec/reservations_spec.rb b/spec/reservations_spec.rb index 7b31e2062..d07825ccf 100644 --- a/spec/reservations_spec.rb +++ b/spec/reservations_spec.rb @@ -2,14 +2,11 @@ require 'pry' describe "Reservation" do - before do - @hotel_ada = Hotel::ReservationManager.new(20) - @new_reservation = @hotel_ada.reserve_room("2018-08-23", "2018-08-25") - end - describe "Initializes an instance of reservation and its instance methods" do before do - @test_reservation = Hotel::Reservation.new(1, check_in: "2018-09-18", check_out: "2018-09-20") + @hotel_ada = Hotel::ReservationManager.new(20) + @new_reservation = @hotel_ada.reserve_room("2018-08-23", "2018-08-25") + @test_reservation = @hotel_ada.reserve_room("2018-09-18", "2018-09-20") end it "creates an instance of Reservation" do @@ -21,8 +18,12 @@ end it "checks to see if there are any reservations for a given date" do -#binding.pry expect(@test_reservation.find_reservation("2018-09-19")).must_equal true end + + it "calulates total cost for a reservation" do +#binding.pry + expect(@test_reservation.total_cost).must_equal 400 + end end end From 9a0fbe505f9b6f921844edd5b2470ef7539f48c3 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 11 Sep 2018 21:17:26 -0700 Subject: [PATCH 20/41] trying to debug is_booked, returning false for everything --- lib/reservations_manager.rb | 9 +-- lib/room.rb | 35 +++++++----- spec/reservations_manager_spec.rb | 93 ++++++++++++++++++------------- 3 files changed, 82 insertions(+), 55 deletions(-) diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index da6ef688c..398ef4fa4 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -41,10 +41,11 @@ def reserve_room(check_in, check_out) end - # def available_rooms(check_in, check_out) - # available_rooms = @reservations.reject {rooms != date_range} - # #loop through Reservations @match dates on the reservations#reject dates that match - # return available_rooms #array + def available_rooms(check_in, check_out) + available_rooms = self.rooms.select {|room| room.is_booked?(check_in, check_out) == false} + #loop through Reservations @match dates on the reservations#reject dates that match + return available_rooms #array + end # def @reservations.all # return @reservations diff --git a/lib/room.rb b/lib/room.rb index cf4a3e14c..6eb6fbc88 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -11,19 +11,28 @@ def initialize(number) @reservations = [] #define room as physical space end - #create helper methods that return boolean values - in reservmgr - create loop methods that take helper method booleans and creates an array - # def self.find_room(id) - # if room.id == id - # return room - # end - # end - - #wave 2 def is_available(check_in:, check_out:) - # date_range = Date.parse(check_in)..Date.parse(check_out) - # #loop through room reservations, reject rooms with reservations that conflict with - # #requested date range - # self.reservations.reject {@reservations} date_range - # # end + #create helper methods that return boolean values - in reservmgr - create loop methods that take helper method booleans and creates an array + # def self.find_room(id) + # if room.id == id + # return room + # end + # end + # + # def find_reservation(date) + # date = Date.parse(date) + # return self.date_range.include? date # end + + def is_booked?(check_in, check_out) + check_dates = Date.parse(check_in)...Date.parse(check_out) + return false if self.reservations.length == 0 + self.reservations.each do |reservation| + if reservation.date_range.include? check_dates || Date.parse(check_in) + return true + end + end + return false + end + end end diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 0d3214841..2f9129052 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -5,6 +5,19 @@ describe "ReservationManager" do before do @hotel_ada = Hotel::ReservationManager.new(20) + @dateA = '2018-08-09' + @dateB = '2018-08-15' + @dateC = '2018-08-20' + @dateD = '2018-08-23' + @dateE ='2018-08-25' + @dateF = '2018-08-27' + @test_date = '2018-08-20' + + @new_reservation1 = @hotel_ada.reserve_room(@dateA, @dateC) + @new_reservation2 = @hotel_ada.reserve_room(@dateB, @dateD) + @new_reservation3 = @hotel_ada.reserve_room(@dateE, @dateF) + @new_reservation4 = @hotel_ada.reserve_room(@dateA, @dateD) + @new_reservation5 = @hotel_ada.reserve_room(@dateC, @dateD) end describe "Initialize ReservationsManager" do @@ -20,34 +33,28 @@ expect(@hotel_ada.rooms).must_be_kind_of Array expect(@hotel_ada.rooms[0]).must_be_instance_of Hotel::Room end - - # wave 2 it "returns a list of all available rooms" do - # expect(@hotel_ada.available_rooms(check_in:"08.23.2018", check_out:"08.25.2018")).must_be_kind_of Array - # expect(@hotel_ada.available_rooms(check_in:"08.23.2018", check_out:"08.25.2018")[0]).must_be_kind_of Hotel::Room - # #expect(@hotel_ada.available_rooms("08.23.2018", "08.25.2018")[0].id).must_equal #rooom ID - # end end describe "reserve_room ReservationManager" do - before do - @hotel_ada = Hotel::ReservationManager.new(20) - @dateA = '2018-08-09' - @dateB = '2018-08-15' - @dateC = '2018-08-20' - @dateD = '2018-08-23' - @dateE = '2018-08-25' - @dateF = '2018-08-27' - @test_date ='2018-08-20' - - @new_reservation1 = @hotel_ada.reserve_room(@dateA, @dateC) - @new_reservation2 = @hotel_ada.reserve_room(@dateB, @dateD) - @new_reservation3 = @hotel_ada.reserve_room(@dateE, @dateF) - @new_reservation4 = @hotel_ada.reserve_room(@dateA, @dateD) - @new_reservation5 = @hotel_ada.reserve_room(@dateC, @dateD) - - - end + # before do + # @hotel_ada = Hotel::ReservationManager.new(20) + # @dateA = '2018-08-09' + # @dateB = '2018-08-15' + # @dateC = '2018-08-20' + # @dateD = '2018-08-23' + # @dateE = '2018-08-25' + # @dateF = '2018-08-27' + # @test_date ='2018-08-20' + # + # @new_reservation1 = @hotel_ada.reserve_room(@dateA, @dateC) + # @new_reservation2 = @hotel_ada.reserve_room(@dateB, @dateD) + # @new_reservation3 = @hotel_ada.reserve_room(@dateE, @dateF) + # @new_reservation4 = @hotel_ada.reserve_room(@dateA, @dateD) + # @new_reservation5 = @hotel_ada.reserve_room(@dateC, @dateD) + # + # + # end it "can reserve a room for a given date range" do expect(@new_reservation1).must_be_instance_of Hotel::Reservation @@ -69,20 +76,20 @@ describe "it can list all reservations for a given date" do before do - @hotel_ada = Hotel::ReservationManager.new(20) - @dateA = '2018-08-09' - @dateB = '2018-08-15' - @dateC = '2018-08-20' - @dateD = '2018-08-23' - @dateE ='2018-08-25' - @dateF = '2018-08-27' - @test_date = '2018-08-20' - - @new_reservation1 = @hotel_ada.reserve_room(@dateA, @dateC) - @new_reservation2 = @hotel_ada.reserve_room(@dateB, @dateD) - @new_reservation3 = @hotel_ada.reserve_room(@dateE, @dateF) - @new_reservation4 = @hotel_ada.reserve_room(@dateA, @dateD) - @new_reservation5 = @hotel_ada.reserve_room(@dateC, @dateD) + # @hotel_ada = Hotel::ReservationManager.new(20) + # @dateA = '2018-08-09' + # @dateB = '2018-08-15' + # @dateC = '2018-08-20' + # @dateD = '2018-08-23' + # @dateE ='2018-08-25' + # @dateF = '2018-08-27' + # @test_date = '2018-08-20' + # + # @new_reservation1 = @hotel_ada.reserve_room(@dateA, @dateC) + # @new_reservation2 = @hotel_ada.reserve_room(@dateB, @dateD) + # @new_reservation3 = @hotel_ada.reserve_room(@dateE, @dateF) + # @new_reservation4 = @hotel_ada.reserve_room(@dateA, @dateD) + # @new_reservation5 = @hotel_ada.reserve_room(@dateC, @dateD) end it "returns a list of rooms for given date" do @@ -92,6 +99,16 @@ expect(@hotel_ada.booked_reservations(@test_date).length).must_equal 3 end end + + describe "Wave 2 - Return list of available rooms for given date range" do + it "returns a list of availble rooms for given date" do + expect(@hotel_ada.available_rooms('2018-08-23', '2018-08-25')).must_be_kind_of Array + # binding.pry + expect(@hotel_ada.available_rooms('2018-08-23', '2018-08-25').length).must_equal 19 + expect(@hotel_ada.available_rooms('2018-08-23', '2018-08-25')[0]).must_be_kind_of Hotel::Room + #expect(@hotel_ada.available_rooms("08.23.2018", "08.25.2018")[0].id).must_equal #rooom ID + end + end end # describe "List all rooms " From 224ff5cb652be91fc2f80f49939d6c0e8281504b Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 11 Sep 2018 21:27:42 -0700 Subject: [PATCH 21/41] fixed bug in available rooms method --- lib/reservations.rb | 6 +++--- lib/reservations_manager.rb | 2 +- lib/room.rb | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 86669cb2c..05fc0299f 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -24,9 +24,9 @@ def find_reservation(date) #check overlap #reservations_manager.reservations - def do_conflict?(dates) - reservation.date_range.include? date - end + # def do_conflict?(dates) + # reservation.date_range.include? date + # end # def self.calculate_reservation_cost # total_cost = @rooms.length * @date_range.count * COST_OF_ROOM diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 398ef4fa4..e8809d29d 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -33,7 +33,7 @@ def booked_reservations(date) def reserve_room(check_in, check_out) new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) - assigned_room = @rooms[0]#available_rooms + assigned_room = available_rooms(check_in, check_out).last#available_rooms new_reservation.rooms << assigned_room.id find_room(assigned_room.id).reservations << new_reservation @reservations << new_reservation diff --git a/lib/room.rb b/lib/room.rb index 6eb6fbc88..947e22043 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -23,11 +23,12 @@ def initialize(number) # return self.date_range.include? date # end + def is_booked?(check_in, check_out) check_dates = Date.parse(check_in)...Date.parse(check_out) return false if self.reservations.length == 0 self.reservations.each do |reservation| - if reservation.date_range.include? check_dates || Date.parse(check_in) + if reservation.find_reservation(check_in) || reservation.find_reservation(check_out) return true end end From 8079dd072f0dcb144995b8a41f4c3ac39e0d6e47 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 11 Sep 2018 22:08:29 -0700 Subject: [PATCH 22/41] fixed some tests for available_rooms --- lib/reservations_manager.rb | 2 +- spec/reservations_manager_spec.rb | 48 ++++++------------------------- 2 files changed, 9 insertions(+), 41 deletions(-) diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index e8809d29d..7ea054556 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -33,7 +33,7 @@ def booked_reservations(date) def reserve_room(check_in, check_out) new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) - assigned_room = available_rooms(check_in, check_out).last#available_rooms + assigned_room = available_rooms(check_in, check_out).last #available_rooms new_reservation.rooms << assigned_room.id find_room(assigned_room.id).reservations << new_reservation @reservations << new_reservation diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 2f9129052..99183e475 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -37,61 +37,29 @@ describe "reserve_room ReservationManager" do - # before do - # @hotel_ada = Hotel::ReservationManager.new(20) - # @dateA = '2018-08-09' - # @dateB = '2018-08-15' - # @dateC = '2018-08-20' - # @dateD = '2018-08-23' - # @dateE = '2018-08-25' - # @dateF = '2018-08-27' - # @test_date ='2018-08-20' - # - # @new_reservation1 = @hotel_ada.reserve_room(@dateA, @dateC) - # @new_reservation2 = @hotel_ada.reserve_room(@dateB, @dateD) - # @new_reservation3 = @hotel_ada.reserve_room(@dateE, @dateF) - # @new_reservation4 = @hotel_ada.reserve_room(@dateA, @dateD) - # @new_reservation5 = @hotel_ada.reserve_room(@dateC, @dateD) - # - # - # end - it "can reserve a room for a given date range" do expect(@new_reservation1).must_be_instance_of Hotel::Reservation +#binding.pry expect(@new_reservation1.id).must_equal 1 + expect(@new_reservation5.id).must_equal 5 expect(@new_reservation1.check_in).must_be_instance_of Date end it "adds room id to the reservation" do expect(@new_reservation1.rooms).must_be_kind_of Array - expect(@new_reservation1.rooms[0]).must_equal 1 + expect(@new_reservation1.rooms[0]).must_equal 20 + expect(@new_reservation4.rooms[0]).must_equal 19 # llook for room with availability conflict end it "adds the reservation to the instance of room" do expect(@hotel_ada.rooms[0].reservations).must_be_kind_of Array - expect(@hotel_ada.rooms[0].reservations[0]).must_be_instance_of Hotel:: Reservation - expect(@hotel_ada.rooms[0].reservations[0].id).must_equal 1 + expect(@hotel_ada.rooms[19].reservations[0]).must_be_instance_of Hotel:: Reservation + expect(@hotel_ada.rooms[19].reservations[0].id).must_equal 1 end end describe "it can list all reservations for a given date" do - before do - # @hotel_ada = Hotel::ReservationManager.new(20) - # @dateA = '2018-08-09' - # @dateB = '2018-08-15' - # @dateC = '2018-08-20' - # @dateD = '2018-08-23' - # @dateE ='2018-08-25' - # @dateF = '2018-08-27' - # @test_date = '2018-08-20' - # - # @new_reservation1 = @hotel_ada.reserve_room(@dateA, @dateC) - # @new_reservation2 = @hotel_ada.reserve_room(@dateB, @dateD) - # @new_reservation3 = @hotel_ada.reserve_room(@dateE, @dateF) - # @new_reservation4 = @hotel_ada.reserve_room(@dateA, @dateD) - # @new_reservation5 = @hotel_ada.reserve_room(@dateC, @dateD) - end it "returns a list of rooms for given date" do expect(@hotel_ada.booked_reservations(@test_date)).must_be_kind_of Array #binding.pry @@ -104,8 +72,8 @@ it "returns a list of availble rooms for given date" do expect(@hotel_ada.available_rooms('2018-08-23', '2018-08-25')).must_be_kind_of Array # binding.pry - expect(@hotel_ada.available_rooms('2018-08-23', '2018-08-25').length).must_equal 19 - expect(@hotel_ada.available_rooms('2018-08-23', '2018-08-25')[0]).must_be_kind_of Hotel::Room + expect(@hotel_ada.available_rooms('2018-08-18', '2018-08-20').length).must_equal 17 + expect(@hotel_ada.available_rooms('2018-08-18', '2018-08-20')[0]).must_be_kind_of Hotel::Room #expect(@hotel_ada.available_rooms("08.23.2018", "08.25.2018")[0].id).must_equal #rooom ID end end From 7ab2ea27710a838ef4102b72fddb3b3492298b7f Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 11 Sep 2018 23:06:28 -0700 Subject: [PATCH 23/41] added overlaps? method to make a helper for is_booked.. sandi metz is probably sad --- lib/reservations.rb | 14 +++++++++++++- lib/room.rb | 7 +++++-- spec/reservations_manager_spec.rb | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 05fc0299f..e8fddc393 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -6,7 +6,7 @@ module Hotel class Reservation attr_reader :id, :check_in, :check_out, :rooms, :total_cost, :date_range - attr_accessor :total_cost + def initialize(number, check_in:, check_out:) @id = number @@ -22,6 +22,18 @@ def find_reservation(date) return self.date_range.include? date end + def overlaps?(check_in, check_out) + existing_check_in = self.check_in + existing_check_out = self.check_out + if existing_check_in < check_out && existing_check_in > check_in + return true + elsif check_in < existing_check_out && existing_check_out < check_out + else + return false + end + end + + #check overlap #reservations_manager.reservations # def do_conflict?(dates) diff --git a/lib/room.rb b/lib/room.rb index 947e22043..184a88589 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -25,11 +25,14 @@ def initialize(number) def is_booked?(check_in, check_out) - check_dates = Date.parse(check_in)...Date.parse(check_out) + check_in = Date.parse(check_in) + check_out = Date.parse(check_out) + check_dates = check_in...check_out return false if self.reservations.length == 0 self.reservations.each do |reservation| - if reservation.find_reservation(check_in) || reservation.find_reservation(check_out) + if reservation.date_range.cover?(check_dates) return true + elsif reservation.overlaps?(check_in, check_out) end end return false diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 99183e475..b83f5f028 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -71,7 +71,7 @@ describe "Wave 2 - Return list of available rooms for given date range" do it "returns a list of availble rooms for given date" do expect(@hotel_ada.available_rooms('2018-08-23', '2018-08-25')).must_be_kind_of Array - # binding.pry + # binding.pry expect(@hotel_ada.available_rooms('2018-08-18', '2018-08-20').length).must_equal 17 expect(@hotel_ada.available_rooms('2018-08-18', '2018-08-20')[0]).must_be_kind_of Hotel::Room #expect(@hotel_ada.available_rooms("08.23.2018", "08.25.2018")[0].id).must_equal #rooom ID From 70f1cc133eb9e60cb595d8f2a6cedaa6e7c7c5b9 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 11 Sep 2018 23:24:07 -0700 Subject: [PATCH 24/41] fixed available rooms method, need to add more tests --- lib/reservations.rb | 5 +++-- lib/room.rb | 1 + spec/reservations_manager_spec.rb | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index e8fddc393..294453eb8 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -25,9 +25,10 @@ def find_reservation(date) def overlaps?(check_in, check_out) existing_check_in = self.check_in existing_check_out = self.check_out - if existing_check_in < check_out && existing_check_in > check_in + if existing_check_in <= check_out && existing_check_in >= check_in + return true + elsif check_in <= existing_check_out && existing_check_out <= check_out return true - elsif check_in < existing_check_out && existing_check_out < check_out else return false end diff --git a/lib/room.rb b/lib/room.rb index 184a88589..5902593da 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -33,6 +33,7 @@ def is_booked?(check_in, check_out) if reservation.date_range.cover?(check_dates) return true elsif reservation.overlaps?(check_in, check_out) + return true end end return false diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index b83f5f028..afe3a5181 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -48,7 +48,7 @@ it "adds room id to the reservation" do expect(@new_reservation1.rooms).must_be_kind_of Array expect(@new_reservation1.rooms[0]).must_equal 20 - expect(@new_reservation4.rooms[0]).must_equal 19 # llook for room with availability conflict + expect(@new_reservation5.rooms[0]).must_equal 17 # llook for room with availability conflict end it "adds the reservation to the instance of room" do @@ -70,10 +70,10 @@ describe "Wave 2 - Return list of available rooms for given date range" do it "returns a list of availble rooms for given date" do - expect(@hotel_ada.available_rooms('2018-08-23', '2018-08-25')).must_be_kind_of Array - # binding.pry - expect(@hotel_ada.available_rooms('2018-08-18', '2018-08-20').length).must_equal 17 - expect(@hotel_ada.available_rooms('2018-08-18', '2018-08-20')[0]).must_be_kind_of Hotel::Room + expect(@hotel_ada.available_rooms('2018-08-20', '2018-08-23')).must_be_kind_of Array + #binding.pry + expect(@hotel_ada.available_rooms('2018-08-20', '2018-08-23').length).must_equal 16 + expect(@hotel_ada.available_rooms('2018-08-20', '2018-08-23')[0]).must_be_kind_of Hotel::Room #expect(@hotel_ada.available_rooms("08.23.2018", "08.25.2018")[0].id).must_equal #rooom ID end end From 16808df7014f67838484eb42ddc248b12985ddd7 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 11 Sep 2018 23:44:45 -0700 Subject: [PATCH 25/41] added argument error for invalid dates --- lib/reservations.rb | 6 ++++++ spec/reservations_manager_spec.rb | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/reservations.rb b/lib/reservations.rb index 294453eb8..1ff45c1f6 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -15,6 +15,12 @@ def initialize(number, check_in:, check_out:) @date_range = (@check_in...@check_out) @rooms = []#instance of a room # reconsider- might not need but maybe @total_cost = @date_range.count * COST_OF_ROOM #wanted it to be @rooms.length * + + if @check_out != nil + if @check_out <= @check_in + raise ArgumentError, "Invalid date range" + end + end end def find_reservation(date) diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index afe3a5181..0af1b5109 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -25,6 +25,15 @@ expect(@hotel_ada).must_be_instance_of Hotel::ReservationManager expect(@hotel_ada.reservations).must_be_kind_of Array end + + it "raise an argumenterror for invalid date range" do + expect { + new_reservation6 = @hotel_ada.reserve_room(@dateD, @dateC) + }.must_raise ArgumentError + expect { + new_reservation7 = @hotel_ada.reserve_room(@dateD, @dateD) + }.must_raise ArgumentError + end end describe "Access all rooms" do From dc3cc35f43a974310a5781738d955c6270a05637 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Wed, 12 Sep 2018 00:06:09 -0700 Subject: [PATCH 26/41] added block method --- lib/reservations.rb | 1 + lib/reservations_manager.rb | 17 ++++++++++++++++- spec/reservations_manager_spec.rb | 15 +++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 1ff45c1f6..a7ae4c989 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -16,6 +16,7 @@ def initialize(number, check_in:, check_out:) @rooms = []#instance of a room # reconsider- might not need but maybe @total_cost = @date_range.count * COST_OF_ROOM #wanted it to be @rooms.length * + #change this to standard error / rescue if @check_out != nil if @check_out <= @check_in raise ArgumentError, "Invalid date range" diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 7ea054556..8589371c2 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -26,7 +26,7 @@ def find_room(id) end def booked_reservations(date) - return reservations = @reservations.select {|reservation| reservation.find_reservation(date) == true} + return @reservations.select {|reservation| reservation.find_reservation(date) == true} end # return booked_rooms #array #use same find_reservation method for rooms select for available, reject for booked @@ -47,6 +47,21 @@ def available_rooms(check_in, check_out) return available_rooms #array end + def reserve_block(number_of_rooms, check_in, check_out) + while available_rooms(check_in, check_out).length > number_of_rooms + block_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) + assigned_rooms = available_rooms(check_in, check_out).first(number_of_rooms) + assigned_rooms.each do |room| + block_reservation.rooms << room.id + find_room(room.id).reservations << block_reservation + end + end + @reservations << block_reservation + return block_reservation + end + + + # def @reservations.all # return @reservations # end diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 0af1b5109..34f8c42ce 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -28,10 +28,10 @@ it "raise an argumenterror for invalid date range" do expect { - new_reservation6 = @hotel_ada.reserve_room(@dateD, @dateC) + @hotel_ada.reserve_room(@dateD, @dateC) }.must_raise ArgumentError expect { - new_reservation7 = @hotel_ada.reserve_room(@dateD, @dateD) + @hotel_ada.reserve_room(@dateD, @dateD) }.must_raise ArgumentError end end @@ -86,6 +86,17 @@ #expect(@hotel_ada.available_rooms("08.23.2018", "08.25.2018")[0].id).must_equal #rooom ID end end + + describe "Wave 3 - Reserve Block rooms" do + before do + @block_test = @hotel_ada.reserve_block(3, '2018-08-20', '2018-08-23') + end + it "allows you to reserve multiple rooms" do + expect(@block_test).must_be_instance_of Hotel::Reservation + expect(@block_test.id).must_equal 6 + expect(@block_test.rooms.length).must_equal 3 + end + end end # describe "List all rooms " From a00b55d8ad9452673c28f8557066246911c45e9e Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Wed, 12 Sep 2018 00:14:49 -0700 Subject: [PATCH 27/41] fixing total cost method --- lib/reservations.rb | 15 ++++++++++----- lib/reservations_manager.rb | 2 +- spec/reservations_manager_spec.rb | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index a7ae4c989..7ce36cee0 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -14,7 +14,7 @@ def initialize(number, check_in:, check_out:) @check_out = Date.parse(check_out) @date_range = (@check_in...@check_out) @rooms = []#instance of a room # reconsider- might not need but maybe - @total_cost = @date_range.count * COST_OF_ROOM #wanted it to be @rooms.length * + @total_cost = self.calculate_reservation_cost #wanted it to be @rooms.length * #change this to standard error / rescue if @check_out != nil @@ -48,9 +48,14 @@ def overlaps?(check_in, check_out) # reservation.date_range.include? date # end - # def self.calculate_reservation_cost - # total_cost = @rooms.length * @date_range.count * COST_OF_ROOM - # return total_cost - # end + def self.calculate_reservation_cost + if @rooms.length > 1 + total_cost = @date_range.count * @rooms.length * COST_OF_ROOM * discount_rate + else + total_cost = @date_range.count * COST_OF_ROOM + end + @total_cost = total_cost + return total_cost + end end end diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 8589371c2..1b045ce36 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -47,7 +47,7 @@ def available_rooms(check_in, check_out) return available_rooms #array end - def reserve_block(number_of_rooms, check_in, check_out) + def reserve_block(number_of_rooms, check_in, check_out, discount_rate: 0.80) while available_rooms(check_in, check_out).length > number_of_rooms block_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) assigned_rooms = available_rooms(check_in, check_out).first(number_of_rooms) diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 34f8c42ce..e8b0fbe76 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -95,6 +95,7 @@ expect(@block_test).must_be_instance_of Hotel::Reservation expect(@block_test.id).must_equal 6 expect(@block_test.rooms.length).must_equal 3 + expect(@block_test.total_cost).must_equal 1440 end end end From 74a930a361cff652afb69cc4e469a7e7846ab154 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Wed, 12 Sep 2018 09:27:13 -0700 Subject: [PATCH 28/41] fix block, currently handling multiple rooms in a re, not a block --- lib/reservations.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 7ce36cee0..c445bcee4 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -14,7 +14,7 @@ def initialize(number, check_in:, check_out:) @check_out = Date.parse(check_out) @date_range = (@check_in...@check_out) @rooms = []#instance of a room # reconsider- might not need but maybe - @total_cost = self.calculate_reservation_cost #wanted it to be @rooms.length * + # @total_cost = self.calculate_reservation_cost #wanted it to be @rooms.length * #change this to standard error / rescue if @check_out != nil @@ -51,11 +51,11 @@ def overlaps?(check_in, check_out) def self.calculate_reservation_cost if @rooms.length > 1 total_cost = @date_range.count * @rooms.length * COST_OF_ROOM * discount_rate - else - total_cost = @date_range.count * COST_OF_ROOM + else @rooms.length == 1 + total_cost = @date_range.count * COST_OF_ROOM end - @total_cost = total_cost return total_cost end + end end From aa11f95fd5a7edc9a0666b58e2b26c97de5b4267 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Wed, 12 Sep 2018 10:39:30 -0700 Subject: [PATCH 29/41] fixed total cost method --- lib/reservations.rb | 22 +++++++--------------- lib/reservations_manager.rb | 2 +- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index c445bcee4..566651d1b 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -8,14 +8,13 @@ class Reservation - def initialize(number, check_in:, check_out:) + def initialize(number, check_in:, check_out:, discount_rate: 1) @id = number @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) @date_range = (@check_in...@check_out) - @rooms = []#instance of a room # reconsider- might not need but maybe - # @total_cost = self.calculate_reservation_cost #wanted it to be @rooms.length * - + @rooms = [] + @discount_rate = discount_rate #change this to standard error / rescue if @check_out != nil if @check_out <= @check_in @@ -41,21 +40,14 @@ def overlaps?(check_in, check_out) end end - - #check overlap - #reservations_manager.reservations - # def do_conflict?(dates) - # reservation.date_range.include? date - # end - - def self.calculate_reservation_cost - if @rooms.length > 1 - total_cost = @date_range.count * @rooms.length * COST_OF_ROOM * discount_rate + def total_cost + if self.rooms.length > 1 + total_cost = @date_range.count * @rooms.length * COST_OF_ROOM * @discount_rate else @rooms.length == 1 total_cost = @date_range.count * COST_OF_ROOM end return total_cost end - + end end diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 1b045ce36..72f2c85f1 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -49,7 +49,7 @@ def available_rooms(check_in, check_out) def reserve_block(number_of_rooms, check_in, check_out, discount_rate: 0.80) while available_rooms(check_in, check_out).length > number_of_rooms - block_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) + block_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out, discount_rate: discount_rate) assigned_rooms = available_rooms(check_in, check_out).first(number_of_rooms) assigned_rooms.each do |room| block_reservation.rooms << room.id From f612f12e58cda7be306549e7ee430ff9f5c8ce7c Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Wed, 12 Sep 2018 10:56:31 -0700 Subject: [PATCH 30/41] fixed total cost method --- lib/reservations.rb | 10 +++------- lib/reservations_manager.rb | 1 - 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 566651d1b..d6bae51da 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -4,11 +4,11 @@ module Hotel COST_OF_ROOM = 200 class Reservation - attr_reader :id, :check_in, :check_out, :rooms, :total_cost, :date_range + attr_reader :id, :check_in, :check_out, :rooms, :total_cost, :date_range, :discount_rate - def initialize(number, check_in:, check_out:, discount_rate: 1) + def initialize(number, number_of_rooms:1, check_in:, check_out:, discount_rate: 1) @id = number @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) @@ -41,11 +41,7 @@ def overlaps?(check_in, check_out) end def total_cost - if self.rooms.length > 1 - total_cost = @date_range.count * @rooms.length * COST_OF_ROOM * @discount_rate - else @rooms.length == 1 - total_cost = @date_range.count * COST_OF_ROOM - end + total_cost = self.date_range.count * self.rooms.length * COST_OF_ROOM * self.discount_rate return total_cost end diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 72f2c85f1..fdc9fc86d 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -40,7 +40,6 @@ def reserve_room(check_in, check_out) return new_reservation end - def available_rooms(check_in, check_out) available_rooms = self.rooms.select {|room| room.is_booked?(check_in, check_out) == false} #loop through Reservations @match dates on the reservations#reject dates that match From e63259fb3014634f6911a4ef700744521b8c9e17 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Wed, 12 Sep 2018 13:06:03 -0700 Subject: [PATCH 31/41] added tests for block method and class --- lib/block.rb | 0 lib/reservations_manager.rb | 48 ++++++++++++++++++++----------- spec/reservations_manager_spec.rb | 23 +++++++++++---- 3 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 lib/block.rb diff --git a/lib/block.rb b/lib/block.rb new file mode 100644 index 000000000..e69de29bb diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index fdc9fc86d..c3de6c8ad 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -11,6 +11,7 @@ class ReservationManager def initialize(number_of_rooms) @reservations = [] + @blocks = [] @rooms = [] (1..number_of_rooms).each do |number| @rooms << Room.new(number) @@ -28,14 +29,14 @@ def find_room(id) def booked_reservations(date) return @reservations.select {|reservation| reservation.find_reservation(date) == true} end - # return booked_rooms #array - #use same find_reservation method for rooms select for available, reject for booked - def reserve_room(check_in, check_out) + def reserve_room(check_in, check_out, number_of_rooms: 1 ) new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) - assigned_room = available_rooms(check_in, check_out).last #available_rooms - new_reservation.rooms << assigned_room.id - find_room(assigned_room.id).reservations << new_reservation + assigned_rooms = available_rooms(check_in, check_out).last(number_of_rooms) + assigned_rooms.each do |room| + new_reservation.rooms << room.id + find_room(room.id).reservations << new_reservation + end @reservations << new_reservation return new_reservation end @@ -46,19 +47,34 @@ def available_rooms(check_in, check_out) return available_rooms #array end - def reserve_block(number_of_rooms, check_in, check_out, discount_rate: 0.80) - while available_rooms(check_in, check_out).length > number_of_rooms - block_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out, discount_rate: discount_rate) - assigned_rooms = available_rooms(check_in, check_out).first(number_of_rooms) - assigned_rooms.each do |room| - block_reservation.rooms << room.id - find_room(room.id).reservations << block_reservation - end + def create_block(check_in, check_out, number_of_rooms: , discount_rate: 0.8) + block = Block.new(@blocks.length + 1, check_in: check_in, check_out: check_out) + block_rooms = available_rooms(check_in, check_out).first(number_of_rooms) + block.rooms << block_rooms + block_rooms.each do |room| + find_room(room.id).reservations << block end - @reservations << block_reservation - return block_reservation + @blocks << block + return block end + #how to account for multiple rooms for a rservation within a block_reservation + + # add additional room to reservation + + # def reserve_block(number_of_rooms, check_in, check_out, discount_rate: 0.80) + # while available_rooms(check_in, check_out).length > number_of_rooms + # block_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out, discount_rate: discount_rate) + # assigned_rooms = available_rooms(check_in, check_out).first(number_of_rooms) + # assigned_rooms.each do |room| + # block_reservation.rooms << room.id + # find_room(room.id).reservations << block_reservation + # end + # end + # @reservations << block_reservation + # return block_reservation + # end + # def @reservations.all diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index e8b0fbe76..325fe91cb 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -89,14 +89,25 @@ describe "Wave 3 - Reserve Block rooms" do before do - @block_test = @hotel_ada.reserve_block(3, '2018-08-20', '2018-08-23') + @many_rooms_test = @hotel_ada.reserve_room('2018-08-20', '2018-08-23', number_of_rooms: 3) + @block = @hotel_ada.create_block('2018-08-20', '2018-08-23', number_of_rooms: 10, discount_rate: 0.8 ) end - it "allows you to reserve multiple rooms" do - expect(@block_test).must_be_instance_of Hotel::Reservation - expect(@block_test.id).must_equal 6 - expect(@block_test.rooms.length).must_equal 3 - expect(@block_test.total_cost).must_equal 1440 + it "allows you to reserve multiple rooms on one reservation" do + expect(@many_rooms_test).must_be_instance_of Hotel::Reservation + expect(@many_rooms_test.id).must_equal 6 + expect(@many_rooms_test.rooms.length).must_equal 3 + expect(@many_rooms_test.total_cost).must_equal 1800 end + + it "allows you to make multiple reservation in a block of rooms" do + expect(@block).must_be_instance_of Hotel::Block + expect(@block.reservations).must_be_kind_of Array + expect(@block.reservations[0]).must_be_instance_of Hotel::Reservation + expect(@block.rooms).must_be_kind_of Array + expect(@block.rooms[0]).must_be_instance_of Hotel::Room + end + + end end From 2f43112241aeb5be91e2a50000ac6aa4051c26c8 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Wed, 12 Sep 2018 16:35:02 -0700 Subject: [PATCH 32/41] added create block and introduced reserve block room --- lib/block.rb | 27 +++++++++++++++++++++ lib/reservations_manager.rb | 12 ++++++---- lib/room.rb | 2 +- spec/reservations_manager_spec.rb | 39 +++++++++++++++++++------------ 4 files changed, 60 insertions(+), 20 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index e69de29bb..33a1d3927 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -0,0 +1,27 @@ +require 'pry' + + +module Hotel + class Block + + attr_reader :block_rooms, :reservations, :date_range, :check_in, :check_out, :discount_rate, :id + + def initialize(number, check_in:, check_out:, number_of_rooms:1, discount_rate: 0.8) + @id = number + @check_in = Date.parse(check_in) + @check_out = Date.parse(check_out) + @date_range = (@check_in...@check_out) + @block_rooms = [] + @discount_rate = discount_rate + @reservations = [] + #change this to standard error / rescue + if @check_out != nil + if @check_out <= @check_in + raise ArgumentError, "Invalid date range" + end + end + end + + + end +end diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index c3de6c8ad..11ecdc446 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -3,6 +3,7 @@ require_relative 'room' require_relative 'reservations' +require_relative 'block' #reservations manager module Hotel class ReservationManager @@ -48,16 +49,19 @@ def available_rooms(check_in, check_out) end def create_block(check_in, check_out, number_of_rooms: , discount_rate: 0.8) - block = Block.new(@blocks.length + 1, check_in: check_in, check_out: check_out) - block_rooms = available_rooms(check_in, check_out).first(number_of_rooms) - block.rooms << block_rooms - block_rooms.each do |room| + block = Block.new(@blocks.length + 1, check_in: check_in, check_out: check_out, number_of_rooms: number_of_rooms, discount_rate: discount_rate) + rooms_to_hold = available_rooms(check_in, check_out).first(number_of_rooms) + rooms_to_hold.each do |room| + block.block_rooms << room.id find_room(room.id).reservations << block end @blocks << block return block end + def reserve_block(check_in, check_out, number_of_rooms: , block_id: @blocks.last.id) + end + #how to account for multiple rooms for a rservation within a block_reservation # add additional room to reservation diff --git a/lib/room.rb b/lib/room.rb index 5902593da..86c70b6be 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -8,7 +8,7 @@ class Room def initialize(number) @id = number - @reservations = [] + @reservations = [] #bookings - both res/block #define room as physical space end #create helper methods that return boolean values - in reservmgr - create loop methods that take helper method booleans and creates an array diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index 325fe91cb..ab272ac1c 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -27,12 +27,12 @@ end it "raise an argumenterror for invalid date range" do - expect { - @hotel_ada.reserve_room(@dateD, @dateC) - }.must_raise ArgumentError - expect { - @hotel_ada.reserve_room(@dateD, @dateD) - }.must_raise ArgumentError + expect { + @hotel_ada.reserve_room(@dateD, @dateC) + }.must_raise ArgumentError + expect { + @hotel_ada.reserve_room(@dateD, @dateD) + }.must_raise ArgumentError end end @@ -48,7 +48,7 @@ describe "reserve_room ReservationManager" do it "can reserve a room for a given date range" do expect(@new_reservation1).must_be_instance_of Hotel::Reservation -#binding.pry + #binding.pry expect(@new_reservation1.id).must_equal 1 expect(@new_reservation5.id).must_equal 5 expect(@new_reservation1.check_in).must_be_instance_of Date @@ -70,7 +70,7 @@ describe "it can list all reservations for a given date" do it "returns a list of rooms for given date" do - expect(@hotel_ada.booked_reservations(@test_date)).must_be_kind_of Array + expect(@hotel_ada.booked_reservations(@test_date)).must_be_kind_of Array #binding.pry expect(@hotel_ada.booked_reservations(@test_date)[0]).must_be_instance_of Hotel::Reservation expect(@hotel_ada.booked_reservations(@test_date).length).must_equal 3 @@ -80,7 +80,7 @@ describe "Wave 2 - Return list of available rooms for given date range" do it "returns a list of availble rooms for given date" do expect(@hotel_ada.available_rooms('2018-08-20', '2018-08-23')).must_be_kind_of Array - #binding.pry + #binding.pry expect(@hotel_ada.available_rooms('2018-08-20', '2018-08-23').length).must_equal 16 expect(@hotel_ada.available_rooms('2018-08-20', '2018-08-23')[0]).must_be_kind_of Hotel::Room #expect(@hotel_ada.available_rooms("08.23.2018", "08.25.2018")[0].id).must_equal #rooom ID @@ -90,8 +90,10 @@ describe "Wave 3 - Reserve Block rooms" do before do @many_rooms_test = @hotel_ada.reserve_room('2018-08-20', '2018-08-23', number_of_rooms: 3) - @block = @hotel_ada.create_block('2018-08-20', '2018-08-23', number_of_rooms: 10, discount_rate: 0.8 ) + @block = @hotel_ada.create_block('2018-08-20', '2018-08-23', number_of_rooms: 10, discount_rate: 0.8) + @block_reservation = @hotel_ada.reserve_room_in_block('2018-08-20', '2018-08-23', number_of_rooms: 2) #:block_id end + it "allows you to reserve multiple rooms on one reservation" do expect(@many_rooms_test).must_be_instance_of Hotel::Reservation expect(@many_rooms_test.id).must_equal 6 @@ -99,16 +101,23 @@ expect(@many_rooms_test.total_cost).must_equal 1800 end - it "allows you to make multiple reservation in a block of rooms" do + it "can block a given amount of rooms over a date range" do expect(@block).must_be_instance_of Hotel::Block expect(@block.reservations).must_be_kind_of Array - expect(@block.reservations[0]).must_be_instance_of Hotel::Reservation - expect(@block.rooms).must_be_kind_of Array - expect(@block.rooms[0]).must_be_instance_of Hotel::Room + expect(@block.block_rooms).must_be_kind_of Array + expect(@block.block_rooms[0]).must_be_kind_of Integer + expect(@block.block_rooms.length).must_equal 10 + expect(@block.date_range.count).must_equal 3 end + it "allows you to make multiple reservation in a block of rooms" do + expect(@block.reservations[0]).must_be_instance_of Hotel::Reservation + end end + end - # describe "List all rooms " + + +# describe "List all rooms " From f47bc6f1e07189ce49b5c1c9fc389812b682dd36 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Fri, 14 Sep 2018 13:31:52 -0700 Subject: [PATCH 33/41] commented out reserve block, save for next refactor --- lib/reservations_manager.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index 11ecdc446..d52239f64 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -59,8 +59,18 @@ def create_block(check_in, check_out, number_of_rooms: , discount_rate: 0.8) return block end - def reserve_block(check_in, check_out, number_of_rooms: , block_id: @blocks.last.id) - end +# def reserve_block(check_in, check_out, number_of_rooms: , block_id: @blocks.last.id) +# block_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) +# #refer to blok - create find block based on id return blocked rooms +# available_rooms() check_out).last(number_of_rooms) +# assigned_rooms.each do |room| +# new_reservation.rooms << room.id +# find_room(room.id).reservations << new_reservation +# end +# @reservations << block_reservation +# return block_reservation +# end + end #how to account for multiple rooms for a rservation within a block_reservation @@ -89,5 +99,5 @@ def reserve_block(check_in, check_out, number_of_rooms: , block_id: @blocks.last #ask room - do you have availability - end + end From e62cca28111e94ff0a3f969960a31d5f7604c19b Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Fri, 14 Sep 2018 14:34:06 -0700 Subject: [PATCH 34/41] updated refactors.txt --- lib/refactors.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 lib/refactors.txt diff --git a/lib/refactors.txt b/lib/refactors.txt new file mode 100644 index 000000000..1e5ee97fb --- /dev/null +++ b/lib/refactors.txt @@ -0,0 +1,4 @@ +Refactors for Hotel +- change reserve method so it can be used for block reseration +hve it pull rooms from a vairable- that can be plugged in i.e. +available rooms method for any kidn fo reservation and rooms on hold for block reservations From b2ec51e5d6c234fa162a6a2fbd3bf574337be84f Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Mon, 17 Sep 2018 10:15:05 -0700 Subject: [PATCH 35/41] updated refactors.txt --- lib/refactors.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/refactors.txt b/lib/refactors.txt index 1e5ee97fb..7afcbd710 100644 --- a/lib/refactors.txt +++ b/lib/refactors.txt @@ -1,4 +1,6 @@ Refactors for Hotel - change reserve method so it can be used for block reseration hve it pull rooms from a vairable- that can be plugged in i.e. -available rooms method for any kidn fo reservation and rooms on hold for block reservations +available rooms method for any kind of reservation and rooms on hold for block reservations +- figure out how to handle blocked rooms that are not reserved yet and only allow certain people to reserve, m +mayby need to supply block id? From 2d4bb1db5bfe07557d80fdd65e131ef207d668b1 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Tue, 25 Sep 2018 11:04:35 -0500 Subject: [PATCH 36/41] Design-activity --- design-activity.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 design-activity.md diff --git a/design-activity.md b/design-activity.md new file mode 100644 index 000000000..390ff7ab6 --- /dev/null +++ b/design-activity.md @@ -0,0 +1,26 @@ +1. The two implementations have the same classes but their utilization and functionality of the class are different. +2. Implementation A: + - Cart Entry: stores data for individual cart entries + - Shopping Cart: stores a collection of instances of cart entries + - Order: creates and calculates full order details + Implementation B: + - CartEntry: stores data for individual entry and calculates price + - ShoppingCart: stores collection of instances of entries and calculates sum of a cart. + - Order: calculates total order cost including Tax and stores instances of Cart +3. In Implementation A - the classes are heavily dependent upon one another. The Order class depends on the ShoppingCart class and does all of the work. Any changes done in one of the lower classes changes the Order class. + +Implementation B - the classes are still dependent upon each other but are more loosely coupled because each of the classes includes a specific class method that will calculate price. A change in one of the lower classes has less of an event on the Order class. + +4. Data - in both classes each class stores the same data except implementatin B also calculates out price per entry and shopping Cart in addition to just storing quantity and unit price. + +5. Implementation A - The order class stores all the methods and functionality that this program would need to accomplish. It creates an instance of the cart and then calculates it's total cost. + +Implentation B - Each of the classes is able to calculate the cost/price associated with its specific object. This makes the classes more independent of each other. + +6. I think it makes sense to delegate price computation to lower classes and still have total computed in order. Each class is responsible for knowing the information respective to the instances and objects it creates. In implementation A, total_price manipulates instances of the other classes to produce a total. In implementation B, total_price does not directly manipulate instances of other classes but instead calls upon them to use their own methods to give it what it needs. + +7. To include a discount for bulk buying, it would be much easier to implement this new feature in Impmentation B. The variable and corresponding method change could be added to the lower level classes and the class Order would be non the wiser to the change but still deliver what the program needs to accomplish. + +8. Both Implementations mostly stick to the single responsibility principles except for Implementation A's Order class. Implementation A stores data about a cart and calculates its total cost but is also responsible for calculating the costs of the instances in the two other classes. + +9. ImplementationB is more loosely coupled. From 4ef099c216f159d1da09d7c51a60f7928179bab7 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Sun, 30 Sep 2018 19:25:41 -0500 Subject: [PATCH 37/41] updated design activity/refactors --- design-activity.md | 20 +++++++++++++++++++- lib/reservations.rb | 4 ++-- lib/room.rb | 4 ++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/design-activity.md b/design-activity.md index 390ff7ab6..171f8b7d9 100644 --- a/design-activity.md +++ b/design-activity.md @@ -21,6 +21,24 @@ Implentation B - Each of the classes is able to calculate the cost/price associa 7. To include a discount for bulk buying, it would be much easier to implement this new feature in Impmentation B. The variable and corresponding method change could be added to the lower level classes and the class Order would be non the wiser to the change but still deliver what the program needs to accomplish. -8. Both Implementations mostly stick to the single responsibility principles except for Implementation A's Order class. Implementation A stores data about a cart and calculates its total cost but is also responsible for calculating the costs of the instances in the two other classes. +8. Both Implementations mostly stick to the single responsibility principles except for Implementation A's Order class. Implementation A stores data about a cart and calculates its total cost but is also responsible for calculating the costs of the instances in the two other classes. 9. ImplementationB is more loosely coupled. + +-- + +Hotel +- Reservation manager + - manages/creates relationships between rooms and reservations + - Room factory can be moved to the room class. + - There is no code in the lower classes that would directly influence instance variables in this class. + +- Reservation + - holds all pertinent information to a specific instance of reservation + - refactor reservation to be more generic and usable for block rooms. +- Room + - holds all pertinent information to a specific room + - can take on the factory of rooms from ReservationManager Class + +- Block + - manages information specific to a block. diff --git a/lib/reservations.rb b/lib/reservations.rb index d6bae51da..347e901c3 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -8,8 +8,8 @@ class Reservation - def initialize(number, number_of_rooms:1, check_in:, check_out:, discount_rate: 1) - @id = number + def initialize(id_num, number_of_rooms:1, check_in:, check_out:, discount_rate: 1) + @id = id_num @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) @date_range = (@check_in...@check_out) diff --git a/lib/room.rb b/lib/room.rb index 86c70b6be..5d0aed3e8 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -6,8 +6,8 @@ class Room attr_reader :id attr_accessor :reservations - def initialize(number) - @id = number + def initialize(id_num) + @id = id_num @reservations = [] #bookings - both res/block #define room as physical space end From 62d4e089f639e6c55bf4b2fc609edb73db3c9d00 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Sun, 30 Sep 2018 19:29:10 -0500 Subject: [PATCH 38/41] updated refactor/design activity --- README.md | 27 +++++++++++++++++++++++++-- design-activity.md | 2 ++ lib/refactors.txt | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 07dc42bcf..a47a514c8 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ If you are not familiar with what a block of hotel rooms, here is a brief descri ## Before Submissions -Usually by the end of a project, we can look back on what we made with a clearer understanding of what we actually needed. In industry, this is a great time to do a refactor of some sort. For this project however, you're off the hook... for the moment. We will be revisiting our hotels later on on the course, and you may want to make some changes at that point. +Usually by the end of a project, we can look back on what we made with a clearer understanding of what we actually needed. In industry, this is a great time to do a refactor of some sort. For this project however, you're off the hook... for the moment. We will be revisiting our hotels later on on the course, and you may want to make some changes at that point. - Create a new file in the project called `refactors.txt` - Make a short list of the changes that you could make, particularly in terms of naming conventions @@ -139,4 +139,27 @@ You should not be working on these (or even thinking about them) until you have - Create a CLI to interact with your hotel system ## What we're looking for -You can find what instructors will be looking for in the [feedback](feedback.md) markdown document. +You can find what instructors will be looking for in the [feedback](feedback.md) markdown document. + + +Revisiting Hotel +Now that we've got you thinking about design, spend some time to revisit the code you wrote for the Hotel project. For each class in your program, ask yourself the following questions: + +What is this class's responsibility? +You should be able to describe it in a single sentence. +Is this class responsible for exactly one thing? +Does this class take on any responsibility that should be delegated to "lower level" classes? +Is there code in other classes that directly manipulates this class's instance variables? +You might recall writing a file called refactor.txt. Take a look at the refactor plans that you wrote, and consider the following: + +How easy is it to follow your own instructions? +Do these refactors improve the clarity of your code? +Do you still agree with your previous assesment, or could your refactor be further improved? +Activity +Based on the answers to each set of the above questions, 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. + +If you need inspiration, remember that the reference implementation exists. + +Then make the changes! Don't forget to take advantage of all the tests you wrote - if they're well structured, they should quickly inform you when your refactoring breaks something. + +Once you're satisfied, git commit your changes and then push them to GitHub. This will automatically update your pull request. diff --git a/design-activity.md b/design-activity.md index 171f8b7d9..3821468e3 100644 --- a/design-activity.md +++ b/design-activity.md @@ -42,3 +42,5 @@ Hotel - Block - manages information specific to a block. + +My refactors doc was clear but a little bit scant. I think I could've been more thorough and thoughtful in creating it. But combined with the design activities and instructor feedback, I feel like I have a clear idea of what changes need to be made. diff --git a/lib/refactors.txt b/lib/refactors.txt index 7afcbd710..57b020957 100644 --- a/lib/refactors.txt +++ b/lib/refactors.txt @@ -3,4 +3,4 @@ Refactors for Hotel hve it pull rooms from a vairable- that can be plugged in i.e. available rooms method for any kind of reservation and rooms on hold for block reservations - figure out how to handle blocked rooms that are not reserved yet and only allow certain people to reserve, m -mayby need to supply block id? +maybe need to supply block id? From 7cb3090bdb66a65f15d8f7d71eb5f39397893c88 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Sun, 30 Sep 2018 19:41:07 -0500 Subject: [PATCH 39/41] added block spec and changed reserve room method --- spec/block_spec.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 spec/block_spec.rb diff --git a/spec/block_spec.rb b/spec/block_spec.rb new file mode 100644 index 000000000..e69de29bb From 523842a64354bc4f48c57d4f8670ed6a4d49e3d1 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Sun, 30 Sep 2018 21:30:43 -0500 Subject: [PATCH 40/41] pseudo code in reservations method in reservation manager class --- design-activity.md | 4 +++- lib/block.rb | 4 +++- lib/reservations.rb | 3 ++- lib/reservations_manager.rb | 22 ++++++++++++++++------ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/design-activity.md b/design-activity.md index 3821468e3..f7c95bc5e 100644 --- a/design-activity.md +++ b/design-activity.md @@ -36,11 +36,13 @@ Hotel - Reservation - holds all pertinent information to a specific instance of reservation - refactor reservation to be more generic and usable for block rooms. + - Room - holds all pertinent information to a specific room - can take on the factory of rooms from ReservationManager Class - Block - manages information specific to a block. + - remove reservation responsibility from block class -My refactors doc was clear but a little bit scant. I think I could've been more thorough and thoughtful in creating it. But combined with the design activities and instructor feedback, I feel like I have a clear idea of what changes need to be made. +My refactors doc was clear but a little bit scant. I think I could've been more thorough and thoughtful in creating it. But combined with the design activities and instructor feedback, I feel like I have a clear idea of what changes need to be made. diff --git a/lib/block.rb b/lib/block.rb index 33a1d3927..10a23a97f 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -11,7 +11,7 @@ def initialize(number, check_in:, check_out:, number_of_rooms:1, discount_rate: @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) @date_range = (@check_in...@check_out) - @block_rooms = [] + @block_rooms = [] #if i change this to rooms can i use available rooms on it? @discount_rate = discount_rate @reservations = [] #change this to standard error / rescue @@ -22,6 +22,8 @@ def initialize(number, check_in:, check_out:, number_of_rooms:1, discount_rate: end end + def find_block + end end end diff --git a/lib/reservations.rb b/lib/reservations.rb index 347e901c3..73102e953 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -8,8 +8,9 @@ class Reservation - def initialize(id_num, number_of_rooms:1, check_in:, check_out:, discount_rate: 1) + def initialize(id_num, number_of_rooms:1, check_in:, check_out:, discount_rate: 1, block_id:) @id = id_num + @block_id = block_id @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) @date_range = (@check_in...@check_out) diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index d52239f64..f5dd185df 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -14,12 +14,13 @@ def initialize(number_of_rooms) @reservations = [] @blocks = [] @rooms = [] + #move this factory over to room class (1..number_of_rooms).each do |number| @rooms << Room.new(number) end end - def find_room(id) + def find_room(id) #what is this method used for? @rooms.each do |room| if room.id == id return room @@ -31,12 +32,21 @@ def booked_reservations(date) return @reservations.select {|reservation| reservation.find_reservation(date) == true} end - def reserve_room(check_in, check_out, number_of_rooms: 1 ) + def reserve_room(check_in, check_out, number_of_rooms: 1, block_id:) new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) - assigned_rooms = available_rooms(check_in, check_out).last(number_of_rooms) - assigned_rooms.each do |room| - new_reservation.rooms << room.id - find_room(room.id).reservations << new_reservation + if block_id == '' + assigned_rooms = available_rooms(check_in, check_out).last(number_of_rooms) + else block_id == Integer + #find block method + #assigned_rooms = block.block_rooms.available_rooms(check_in, check_out).last(number_of_rooms) + #can i call available rooms on this method? + end + assigned_rooms.each do |room| + new_reservation.rooms << room.id + find_room(room.id).reservations << new_reservation + if block_id == Integer + find_block(block_id).reservation << new_reservation + end end @reservations << new_reservation return new_reservation From 6d54c6d4bf081713db3c29f4626a55d13600e01a Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Mon, 1 Oct 2018 08:28:54 -0700 Subject: [PATCH 41/41] updated available rooms method, fixing reserveroom/block functionality --- lib/block.rb | 12 +++++++----- lib/reservations.rb | 2 +- lib/reservations_manager.rb | 32 ++++++++++++++++++------------- lib/room.rb | 12 +++++++++++- spec/reservations_manager_spec.rb | 8 ++++---- 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index 10a23a97f..ef434d4b3 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -4,14 +4,14 @@ module Hotel class Block - attr_reader :block_rooms, :reservations, :date_range, :check_in, :check_out, :discount_rate, :id + attr_reader :rooms, :reservations, :date_range, :check_in, :check_out, :discount_rate, :id def initialize(number, check_in:, check_out:, number_of_rooms:1, discount_rate: 0.8) @id = number @check_in = Date.parse(check_in) @check_out = Date.parse(check_out) @date_range = (@check_in...@check_out) - @block_rooms = [] #if i change this to rooms can i use available rooms on it? + @rooms = [] #if i change this to rooms can i use available rooms on it? @discount_rate = discount_rate @reservations = [] #change this to standard error / rescue @@ -22,8 +22,10 @@ def initialize(number, check_in:, check_out:, number_of_rooms:1, discount_rate: end end - def find_block - end - + # def available_rooms_in_block(check_in, check_out) + # available_rooms = self.rooms.select {|room| room.is_booked?(check_in, check_out) == false} + # #loop through Reservations @match dates on the reservations#reject dates that match + # return available_rooms #array + # end end end diff --git a/lib/reservations.rb b/lib/reservations.rb index 73102e953..8b6bb80af 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -8,7 +8,7 @@ class Reservation - def initialize(id_num, number_of_rooms:1, check_in:, check_out:, discount_rate: 1, block_id:) + def initialize(id_num, number_of_rooms:1, check_in:, check_out:, discount_rate: 1, block_id:'') @id = id_num @block_id = block_id @check_in = Date.parse(check_in) diff --git a/lib/reservations_manager.rb b/lib/reservations_manager.rb index f5dd185df..d3f80ccaa 100644 --- a/lib/reservations_manager.rb +++ b/lib/reservations_manager.rb @@ -28,19 +28,21 @@ def find_room(id) #what is this method used for? end end + def find_block(block_id) + @blocks.each do |block| + if block.id == id + return block + end + end + end + def booked_reservations(date) return @reservations.select {|reservation| reservation.find_reservation(date) == true} end - def reserve_room(check_in, check_out, number_of_rooms: 1, block_id:) - new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) - if block_id == '' - assigned_rooms = available_rooms(check_in, check_out).last(number_of_rooms) - else block_id == Integer - #find block method - #assigned_rooms = block.block_rooms.available_rooms(check_in, check_out).last(number_of_rooms) - #can i call available rooms on this method? - end + def reserve_room(check_in, check_out, number_of_rooms: 1, block_id:'') + new_reservation = Reservation.new(@reservations.length + 1, number_of_rooms: number_of_rooms, check_in: check_in, check_out: check_out, block_id:block_id) + assigned_rooms = available_rooms(check_in, check_out, block_id:block_id).last(number_of_rooms) assigned_rooms.each do |room| new_reservation.rooms << room.id find_room(room.id).reservations << new_reservation @@ -52,8 +54,12 @@ def reserve_room(check_in, check_out, number_of_rooms: 1, block_id:) return new_reservation end - def available_rooms(check_in, check_out) - available_rooms = self.rooms.select {|room| room.is_booked?(check_in, check_out) == false} + def available_rooms(check_in, check_out, block_id:'') + if block_id == '' + available_rooms = self.rooms.select {|room| room.is_booked?(check_in, check_out) == false} + elsif block_id == Integer + available_rooms = find_block(block_id).rooms.select {|room| room.is_booked?(check_in, check_out) == false} + end #loop through Reservations @match dates on the reservations#reject dates that match return available_rooms #array end @@ -62,8 +68,8 @@ def create_block(check_in, check_out, number_of_rooms: , discount_rate: 0.8) block = Block.new(@blocks.length + 1, check_in: check_in, check_out: check_out, number_of_rooms: number_of_rooms, discount_rate: discount_rate) rooms_to_hold = available_rooms(check_in, check_out).first(number_of_rooms) rooms_to_hold.each do |room| - block.block_rooms << room.id - find_room(room.id).reservations << block + block.rooms << room.id + find_room(room.id).reservations << block# - this needs to be changed end @blocks << block return block diff --git a/lib/room.rb b/lib/room.rb index 5d0aed3e8..b012c9eea 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -8,9 +8,19 @@ class Room def initialize(id_num) @id = id_num - @reservations = [] #bookings - both res/block + @reservations = [] + #bookings - both res/block #define room as physical space end + + def self.make_rooms(number_of_rooms) + rooms = [] + (1..number_of_rooms).each do |number| + rooms << Room.new(number) + end + return rooms + end + #create helper methods that return boolean values - in reservmgr - create loop methods that take helper method booleans and creates an array # def self.find_room(id) # if room.id == id diff --git a/spec/reservations_manager_spec.rb b/spec/reservations_manager_spec.rb index ab272ac1c..98beb20c4 100644 --- a/spec/reservations_manager_spec.rb +++ b/spec/reservations_manager_spec.rb @@ -91,7 +91,7 @@ before do @many_rooms_test = @hotel_ada.reserve_room('2018-08-20', '2018-08-23', number_of_rooms: 3) @block = @hotel_ada.create_block('2018-08-20', '2018-08-23', number_of_rooms: 10, discount_rate: 0.8) - @block_reservation = @hotel_ada.reserve_room_in_block('2018-08-20', '2018-08-23', number_of_rooms: 2) #:block_id + @block_reservation = @hotel_ada.reserve_room('2018-08-20', '2018-08-23', number_of_rooms: 2, block_id: 1) #:block_id end it "allows you to reserve multiple rooms on one reservation" do @@ -104,9 +104,9 @@ it "can block a given amount of rooms over a date range" do expect(@block).must_be_instance_of Hotel::Block expect(@block.reservations).must_be_kind_of Array - expect(@block.block_rooms).must_be_kind_of Array - expect(@block.block_rooms[0]).must_be_kind_of Integer - expect(@block.block_rooms.length).must_equal 10 + expect(@block.rooms).must_be_kind_of Array + expect(@block.rooms[0]).must_be_kind_of Integer + expect(@block.rooms.length).must_equal 10 expect(@block.date_range.count).must_equal 3 end