From c4c35ba882e93fc89c5d07ef5f0d9a32594bcf07 Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Tue, 5 Sep 2017 15:27:43 -0700 Subject: [PATCH 01/18] Set up files - rake, spec_helper, date range, room, and reservation --- Rakefile | 9 +++++++++ lib/date_range.rb | 0 lib/reservation.rb | 0 lib/room.rb | 10 ++++++++++ specs/date_range.rb | 1 + specs/reservation_spec.rb | 1 + specs/room_spec.rb | 9 +++++++++ specs/spec_helper.rb | 11 +++++++++++ 8 files changed, 41 insertions(+) create mode 100644 Rakefile create mode 100644 lib/date_range.rb create mode 100644 lib/reservation.rb create mode 100644 lib/room.rb create mode 100644 specs/date_range.rb create mode 100644 specs/reservation_spec.rb create mode 100644 specs/room_spec.rb create mode 100644 specs/spec_helper.rb diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..deb52f2cd --- /dev/null +++ b/Rakefile @@ -0,0 +1,9 @@ +require 'rake/testtask' + +Rake::TestTask.new do |t| + t.libs = ["lib"] + t.warning = true + t.test_files = FileList['specs/*_spec.rb'] +end + +task default: :test diff --git a/lib/date_range.rb b/lib/date_range.rb new file mode 100644 index 000000000..e69de29bb diff --git a/lib/reservation.rb b/lib/reservation.rb new file mode 100644 index 000000000..e69de29bb diff --git a/lib/room.rb b/lib/room.rb new file mode 100644 index 000000000..aa23cb8a4 --- /dev/null +++ b/lib/room.rb @@ -0,0 +1,10 @@ +module Hotel + +class Room + + def initialize + end + +end #class + +end #module diff --git a/specs/date_range.rb b/specs/date_range.rb new file mode 100644 index 000000000..ae9c220ea --- /dev/null +++ b/specs/date_range.rb @@ -0,0 +1 @@ +require_relative 'spec_helper' diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb new file mode 100644 index 000000000..ae9c220ea --- /dev/null +++ b/specs/reservation_spec.rb @@ -0,0 +1 @@ +require_relative 'spec_helper' diff --git a/specs/room_spec.rb b/specs/room_spec.rb new file mode 100644 index 000000000..20392641b --- /dev/null +++ b/specs/room_spec.rb @@ -0,0 +1,9 @@ +require_relative 'spec_helper' + +describe "Room class" do + +it "Can be instantiated" do + Hotel::Room.new.must_be_instance_of Hotel::Room +end + +end #describe diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb new file mode 100644 index 000000000..fa04aa484 --- /dev/null +++ b/specs/spec_helper.rb @@ -0,0 +1,11 @@ +require 'simplecov' +SimpleCov.start + +require 'minitest/autorun' +require 'minitest/reporters' + +require_relative '../lib/room' +require_relative '../lib/date_range' +require_relative '../lib/reservation' + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 05cdb2135dfb04ddd4a07b02612bf0fecd7a3165 Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Thu, 7 Sep 2017 10:28:33 -0700 Subject: [PATCH 02/18] Initialize method on DateRange with passing tests --- lib/date_range.rb | 16 ++++++++++++++++ lib/hotel.rb | 29 +++++++++++++++++++++++++++++ lib/reservation.rb | 11 +++++++++++ lib/room.rb | 10 ---------- specs/date_range.rb | 1 - specs/date_range_spec.rb | 25 +++++++++++++++++++++++++ specs/hotel_spec.rb | 25 +++++++++++++++++++++++++ specs/room_spec.rb | 9 --------- specs/spec_helper.rb | 2 +- 9 files changed, 107 insertions(+), 21 deletions(-) create mode 100644 lib/hotel.rb delete mode 100644 lib/room.rb delete mode 100644 specs/date_range.rb create mode 100644 specs/date_range_spec.rb create mode 100644 specs/hotel_spec.rb delete mode 100644 specs/room_spec.rb diff --git a/lib/date_range.rb b/lib/date_range.rb index e69de29bb..44c1ff355 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -0,0 +1,16 @@ +module Hotel + + class DateRange + + attr_reader :check_in, :check_out + + def initialize(year_1, month_1, date_1, year_2, month_2, date_2) + @check_in = Date.new(year_1, month_1, date_1) + @check_out = Date.new(year_2, month_2, date_2) + end + + + + end #class + +end #hotel diff --git a/lib/hotel.rb b/lib/hotel.rb new file mode 100644 index 000000000..24af0c870 --- /dev/null +++ b/lib/hotel.rb @@ -0,0 +1,29 @@ +module Hotel + + class Hotel + + attr_reader :list_of_rooms, :price, :collection_of_reservations + + def initialize(num_of_rooms, price) + @list_of_rooms = [] + room_num = 0 + num_of_rooms.times do |room| + room_num += 1 + @list_of_rooms << room_num + end #loop + + @price = price + @collection_of_reservations = [] + end #initialize + + # def list_of_rooms + # @list_of_rooms.each do |room| + # puts "Room #{room}" + # end + # end #list_of_rooms + # not needed for this more abstract hotel class + + + end #class + +end #module diff --git a/lib/reservation.rb b/lib/reservation.rb index e69de29bb..550648c82 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -0,0 +1,11 @@ +module Hotel + + class Reservation + + def initialize(check_in, check_out, room_num, cost) + end #initialize + + end #reservation + + +end #module diff --git a/lib/room.rb b/lib/room.rb deleted file mode 100644 index aa23cb8a4..000000000 --- a/lib/room.rb +++ /dev/null @@ -1,10 +0,0 @@ -module Hotel - -class Room - - def initialize - end - -end #class - -end #module diff --git a/specs/date_range.rb b/specs/date_range.rb deleted file mode 100644 index ae9c220ea..000000000 --- a/specs/date_range.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative 'spec_helper' diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb new file mode 100644 index 000000000..a43b5f83a --- /dev/null +++ b/specs/date_range_spec.rb @@ -0,0 +1,25 @@ +require_relative 'spec_helper' + +describe "DateRange class" do + # let(:check_in) {Date.new(2017, 9, 4)} + # let(:check_out) {Date.new(2017, 9, 9)} + + #no longer needed because changed the structure of my initialize parameters + # it "Can be instantiated" do + # # check_in = Date.new(2017, 9, 4) + # # check_out = Date.new(2017, 9, 9) + # Hotel::DateRange.new(check_in, check_out).must_be_instance_of Hotel::DateRange + # end + + it "Can be instantiated" do + Hotel::DateRange.new(2017, 9, 4, 2017, 9, 9).must_be_instance_of Hotel::DateRange + end + + it "Allows access to check_in instance variable" do + new_hotel = Hotel::DateRange.new(2017, 9, 4, 2017, 9, 9) + new_hotel.check_in.must_be_instance_of Date + new_hotel.check_out.must_be_instance_of Date + end + + +end diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb new file mode 100644 index 000000000..abf1fcb67 --- /dev/null +++ b/specs/hotel_spec.rb @@ -0,0 +1,25 @@ +require_relative 'spec_helper' + +describe "Room class" do + +it "Can be instantiated" do + Hotel::Hotel.new(20, 200).must_be_instance_of Hotel::Hotel +end + +it "Can create an array of rooms" do + Hotel::Hotel.new(20, 200).list_of_rooms.length.must_equal 20 +end + +it "Can call the array of rooms" do + Hotel::Hotel.new(20,200).list_of_rooms.must_equal [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18, 19, 20] +end + +it "Can call on price of rooms" do + Hotel::Hotel.new(20, 200).price.must_equal 200 +end + +it "can call on collection of reservations array - will be empty" do +Hotel::Hotel.new(20, 200).collection_of_reservations.must_be_instance_of Array +end + +end #describe diff --git a/specs/room_spec.rb b/specs/room_spec.rb deleted file mode 100644 index 20392641b..000000000 --- a/specs/room_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require_relative 'spec_helper' - -describe "Room class" do - -it "Can be instantiated" do - Hotel::Room.new.must_be_instance_of Hotel::Room -end - -end #describe diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index fa04aa484..932a8ee26 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -4,7 +4,7 @@ require 'minitest/autorun' require 'minitest/reporters' -require_relative '../lib/room' +require_relative '../lib/hotel' require_relative '../lib/date_range' require_relative '../lib/reservation' From a0addabbbc904ed02297b9d73b6e2ee538a9a1fa Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Thu, 7 Sep 2017 14:27:04 -0700 Subject: [PATCH 03/18] Changed Date.new to date parse to be able to take in strings and created a check to make sure check in date came before check out --- lib/date_range.rb | 12 +++++++++--- specs/date_range_spec.rb | 21 ++++++++++----------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 44c1ff355..b6f840746 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -1,12 +1,18 @@ +require 'pry' + module Hotel class DateRange attr_reader :check_in, :check_out - def initialize(year_1, month_1, date_1, year_2, month_2, date_2) - @check_in = Date.new(year_1, month_1, date_1) - @check_out = Date.new(year_2, month_2, date_2) + def initialize(check_in, check_out) + @check_in = Date.parse(check_in) + @check_out = Date.parse(check_out) + + if @check_in > @check_out + raise ArgumentError.new("Invalid date range") + end end diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index a43b5f83a..bf228c46b 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -1,25 +1,24 @@ require_relative 'spec_helper' describe "DateRange class" do - # let(:check_in) {Date.new(2017, 9, 4)} - # let(:check_out) {Date.new(2017, 9, 9)} - - #no longer needed because changed the structure of my initialize parameters - # it "Can be instantiated" do - # # check_in = Date.new(2017, 9, 4) - # # check_out = Date.new(2017, 9, 9) - # Hotel::DateRange.new(check_in, check_out).must_be_instance_of Hotel::DateRange - # end + let(:check_in) {"Sept 9 2017"} + let(:check_out) {"Sept 15 2017"} it "Can be instantiated" do - Hotel::DateRange.new(2017, 9, 4, 2017, 9, 9).must_be_instance_of Hotel::DateRange + Hotel::DateRange.new(check_in, check_out).must_be_instance_of Hotel::DateRange end it "Allows access to check_in instance variable" do - new_hotel = Hotel::DateRange.new(2017, 9, 4, 2017, 9, 9) + new_hotel = Hotel::DateRange.new(check_in, check_out) new_hotel.check_in.must_be_instance_of Date new_hotel.check_out.must_be_instance_of Date end + it "Checks for invalid date entry - if check in is after check out date" do + check_in_1 = "Sept 9 2017" + check_out_1 = "Sept 8 2017" + proc {Hotel::DateRange.new(check_in_1, check_out_1)}.must_raise ArgumentError + end + end From 50b6952b39799818a723c52e31097095761fa23c Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Thu, 7 Sep 2017 16:52:43 -0700 Subject: [PATCH 04/18] create total cost method - learned how to call an instance method from other class --- lib/hotel.rb | 6 +++--- lib/reservation.rb | 24 +++++++++++++++++++++++- specs/hotel_spec.rb | 2 +- specs/reservation_spec.rb | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 24af0c870..d3b782afa 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -2,7 +2,7 @@ module Hotel class Hotel - attr_reader :list_of_rooms, :price, :collection_of_reservations + attr_reader :list_of_rooms, :price, :reservation_collection def initialize(num_of_rooms, price) @list_of_rooms = [] @@ -13,7 +13,7 @@ def initialize(num_of_rooms, price) end #loop @price = price - @collection_of_reservations = [] + @reservation_collection = [] end #initialize # def list_of_rooms @@ -22,7 +22,7 @@ def initialize(num_of_rooms, price) # end # end #list_of_rooms # not needed for this more abstract hotel class - + end #class diff --git a/lib/reservation.rb b/lib/reservation.rb index 550648c82..9e02efd65 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,10 +1,32 @@ +require_relative 'date_range'#take note this needs to be included at the top +require 'pry' + module Hotel class Reservation - def initialize(check_in, check_out, room_num, cost) + attr_reader :check_in, :check_out, :date_range, :room_num, :cost, :reservation_array, :num_nights + + def initialize(check_in, check_out, room_num, cost = 200) + @reservation_array = [] + + @date_range = DateRange.new(check_in, check_out) + @reservation_array << @date_range + + @room_num = room_num + @reservation_array << @room_num + + @cost = cost + @reservation_array << @cost + + # @reservation_collection << @reservation_array end #initialize + def total_cost + num_nights = (@date_range.check_out - @date_range.check_in).to_i + return num_nights * @cost + end + end #reservation diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index abf1fcb67..be7b944df 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -19,7 +19,7 @@ end it "can call on collection of reservations array - will be empty" do -Hotel::Hotel.new(20, 200).collection_of_reservations.must_be_instance_of Array +Hotel::Hotel.new(20, 200).reservation_collection.must_be_instance_of Array end end #describe diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index ae9c220ea..0f167cca8 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -1 +1,33 @@ require_relative 'spec_helper' + + +describe "Reservation class" do + + describe "Initialization" do + before do + @hotel = Hotel::Reservation.new('sept 7 2017', 'sept 9 2017', 18) + end + + it "Can be intialized" do + @hotel.must_be_instance_of Hotel::Reservation + end + + it "Can call on instance variables" do + @hotel.date_range.must_be_instance_of Hotel::DateRange #important - need to include Hotel::DateRange; cannot be DateRange alone + @hotel.room_num.must_equal 18 + @hotel.cost.must_equal 200 + end # it + + end #describe + + describe " #total_cost" do + before do + @hotel = Hotel::Reservation.new('sept 7 2017', 'sept 9 2017', 18) + end + + it "Can be called" do + @hotel.total_cost.must_equal 400 + end + end + +end #describe From 94a24d7d58bc1a85e18d9249d8b601ded96f41b1 Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Fri, 8 Sep 2017 13:53:14 -0700 Subject: [PATCH 05/18] add tests to understand what is in the reservation array, beginfleshing out hotel class methods and variables --- lib/hotel.rb | 7 +++++++ lib/reservation.rb | 9 +++++++-- specs/reservation_spec.rb | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index d3b782afa..d3af1c455 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,3 +1,5 @@ +require_relative 'reservation' + module Hotel class Hotel @@ -16,6 +18,11 @@ def initialize(num_of_rooms, price) @reservation_collection = [] end #initialize + def make_reservation + @reservation = Hotel::Reservation.new(check_in, check_out, room_num) + @reservation_collection << @reservation + end + # def list_of_rooms # @list_of_rooms.each do |room| # puts "Room #{room}" diff --git a/lib/reservation.rb b/lib/reservation.rb index 9e02efd65..65d5d91a6 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,11 +1,12 @@ require_relative 'date_range'#take note this needs to be included at the top require 'pry' +require 'Date' module Hotel class Reservation - attr_reader :check_in, :check_out, :date_range, :room_num, :cost, :reservation_array, :num_nights + attr_reader :check_in, :check_out, :date_range, :room_num, :cost, :reservation_array def initialize(check_in, check_out, room_num, cost = 200) @reservation_array = [] @@ -19,7 +20,8 @@ def initialize(check_in, check_out, room_num, cost = 200) @cost = cost @reservation_array << @cost - # @reservation_collection << @reservation_array + + end #initialize def total_cost @@ -31,3 +33,6 @@ def total_cost end #module + +# hotel = Hotel::Reservation.new('sept 9 2016', 'sept 9 2017', 18) +# puts hotel.date_range.check_out diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 0f167cca8..bca9c85f2 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -16,6 +16,9 @@ @hotel.date_range.must_be_instance_of Hotel::DateRange #important - need to include Hotel::DateRange; cannot be DateRange alone @hotel.room_num.must_equal 18 @hotel.cost.must_equal 200 + @hotel.reservation_array.must_include 200 + @hotel.reservation_array.must_be_instance_of Array + @hotel.reservation_array.length.must_equal 3 ##note, I thought here it should be 4, but daterange is one instance so check_in and check_out exist together as daterange instance end # it end #describe @@ -23,10 +26,12 @@ describe " #total_cost" do before do @hotel = Hotel::Reservation.new('sept 7 2017', 'sept 9 2017', 18) + @hotel_2 = Hotel::Reservation.new('oct 22 2017', 'oct 28 2017', 20) end it "Can be called" do @hotel.total_cost.must_equal 400 + @hotel_2.total_cost.must_equal 1200 end end From e489640c7643a4339a05c98c9a56363184410228 Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Fri, 8 Sep 2017 14:59:05 -0700 Subject: [PATCH 06/18] Add #make_reservation Hotel class method with passing tests - lots of time trying to call the right methods --- lib/hotel.rb | 16 ++++++++++---- specs/hotel_spec.rb | 53 +++++++++++++++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index d3af1c455..0ed6d538f 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,10 +1,11 @@ +require 'pry' require_relative 'reservation' module Hotel class Hotel - attr_reader :list_of_rooms, :price, :reservation_collection + attr_reader :list_of_rooms, :price, :reservation_collection, :reservation_made def initialize(num_of_rooms, price) @list_of_rooms = [] @@ -18,9 +19,11 @@ def initialize(num_of_rooms, price) @reservation_collection = [] end #initialize - def make_reservation - @reservation = Hotel::Reservation.new(check_in, check_out, room_num) - @reservation_collection << @reservation + def make_reservation(check_in, check_out, room_num) + @reservation_made = Reservation.new(check_in, check_out, room_num) + # binding.pry + + @reservation_collection << @reservation_made end # def list_of_rooms @@ -34,3 +37,8 @@ def make_reservation end #class end #module + +# my_hotel = Hotel::Hotel.new(20, 200) +# my_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) +# puts my_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) +# puts my_hotel.reservation.room_num.must_equal 4 diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index be7b944df..402dd6473 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -1,25 +1,46 @@ require_relative 'spec_helper' -describe "Room class" do +describe "Hotel class" do -it "Can be instantiated" do - Hotel::Hotel.new(20, 200).must_be_instance_of Hotel::Hotel -end + describe "Instantiation" do -it "Can create an array of rooms" do - Hotel::Hotel.new(20, 200).list_of_rooms.length.must_equal 20 -end + it "Can be instantiated" do + Hotel::Hotel.new(20, 200).must_be_instance_of Hotel::Hotel + end -it "Can call the array of rooms" do - Hotel::Hotel.new(20,200).list_of_rooms.must_equal [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18, 19, 20] -end + it "Can create an array of rooms" do + Hotel::Hotel.new(20, 200).list_of_rooms.length.must_equal 20 + end -it "Can call on price of rooms" do - Hotel::Hotel.new(20, 200).price.must_equal 200 -end + it "Can call the array of rooms" do + Hotel::Hotel.new(20,200).list_of_rooms.must_equal [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18, 19, 20] + end -it "can call on collection of reservations array - will be empty" do -Hotel::Hotel.new(20, 200).reservation_collection.must_be_instance_of Array -end + it "Can call on price of rooms" do + Hotel::Hotel.new(20, 200).price.must_equal 200 + end + it "can call on collection of reservations array - will be empty" do + Hotel::Hotel.new(20, 200).reservation_collection.must_be_instance_of Array + end + end #describe instantiate + + describe "#make reservation" do + before do + @my_hotel = Hotel::Hotel.new(20, 200) + @my_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) + + end + + it "can be instantiated" do + @my_hotel.reservation_made.reservation_array.must_include 4 + @my_hotel.reservation_collection.length.must_equal 1 + end + + it "Can call on class reservation methods" do + # res = @my_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) + @my_hotel.reservation_made.room_num.must_equal 4 + end + + end end #describe From ab0ddc7084f8535a7e64935c31181072bc46f5a8 Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Sat, 9 Sep 2017 12:28:35 -0700 Subject: [PATCH 07/18] wave 1 complete with passing tests --- lib/hotel.rb | 19 ++++++++++++++++++- specs/hotel_spec.rb | 23 ++++++++++++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 0ed6d538f..7e5c0b39d 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -5,7 +5,7 @@ module Hotel class Hotel - attr_reader :list_of_rooms, :price, :reservation_collection, :reservation_made + attr_reader :list_of_rooms, :price, :reservation_collection, :reservation_made, :date_list def initialize(num_of_rooms, price) @list_of_rooms = [] @@ -26,6 +26,18 @@ def make_reservation(check_in, check_out, room_num) @reservation_collection << @reservation_made end + def date_list_of_reservations(date) + @date_list = [] + date = Date.parse(date) + @reservation_collection.each do |entry| + # binding.pry + if entry.date_range.check_in <= date && entry.date_range.check_out >= date + @date_list << [entry.room_num, entry.date_range.check_in.to_s, entry.date_range.check_out.to_s] + end + end + return @date_list + end #def + # def list_of_rooms # @list_of_rooms.each do |room| # puts "Room #{room}" @@ -42,3 +54,8 @@ def make_reservation(check_in, check_out, room_num) # my_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) # puts my_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) # puts my_hotel.reservation.room_num.must_equal 4 + +@bb_hotel = Hotel::Hotel.new(20, 200) +@bb_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) +@bb_hotel.make_reservation('sept 7 2017', 'sept 11 2017', 3) +p @bb_hotel.date_list_of_reservations('sept 9 2017') diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 402dd6473..c823d6ad6 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -27,20 +27,33 @@ describe "#make reservation" do before do - @my_hotel = Hotel::Hotel.new(20, 200) - @my_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) + @bb_hotel = Hotel::Hotel.new(20, 200) + @bb_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) end it "can be instantiated" do - @my_hotel.reservation_made.reservation_array.must_include 4 - @my_hotel.reservation_collection.length.must_equal 1 + @bb_hotel.reservation_made.reservation_array.must_include 4 + @bb_hotel.reservation_collection.length.must_equal 1 end it "Can call on class reservation methods" do # res = @my_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) - @my_hotel.reservation_made.room_num.must_equal 4 + @bb_hotel.reservation_made.room_num.must_equal 4 end end + + describe "#list of reservations for a specific date" do + before do + @bb_hotel = Hotel::Hotel.new(20, 200) + @bb_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) + @bb_hotel.make_reservation('sept 7 2017', 'sept 9 2017', 3) + + end + + it "Returns an array of reservations for that date" do + @bb_hotel.date_list_of_reservations('sept 9 2017').must_be_instance_of Array + end + end end #describe From 3e183d512f69bb38163bb9b78ac7990bcee5884f Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Sat, 9 Sep 2017 12:33:31 -0700 Subject: [PATCH 08/18] remove instance variable of date list in hotel class to local variable --- lib/hotel.rb | 8 ++++---- specs/hotel_spec.rb | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 7e5c0b39d..e40f76049 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -5,7 +5,7 @@ module Hotel class Hotel - attr_reader :list_of_rooms, :price, :reservation_collection, :reservation_made, :date_list + attr_reader :list_of_rooms, :price, :reservation_collection, :reservation_made def initialize(num_of_rooms, price) @list_of_rooms = [] @@ -27,15 +27,15 @@ def make_reservation(check_in, check_out, room_num) end def date_list_of_reservations(date) - @date_list = [] + date_list = [] date = Date.parse(date) @reservation_collection.each do |entry| # binding.pry if entry.date_range.check_in <= date && entry.date_range.check_out >= date - @date_list << [entry.room_num, entry.date_range.check_in.to_s, entry.date_range.check_out.to_s] + date_list << [entry.room_num, entry.date_range.check_in.to_s, entry.date_range.check_out.to_s] end end - return @date_list + return date_list end #def # def list_of_rooms diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index c823d6ad6..dac630ce2 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -54,6 +54,7 @@ it "Returns an array of reservations for that date" do @bb_hotel.date_list_of_reservations('sept 9 2017').must_be_instance_of Array + @bb_hotel.date_list_of_reservations('sept 9 2017').length.must_equal 2 end end end #describe From 45e0568964340a84b48bd848de67ac6d86579a67 Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Sat, 9 Sep 2017 14:06:24 -0700 Subject: [PATCH 09/18] create #room availability given a date range --- lib/hotel.rb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index e40f76049..37fa95dc6 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -45,6 +45,30 @@ def date_list_of_reservations(date) # end #list_of_rooms # not needed for this more abstract hotel class + def room_availability(check_in, check_out) + #can be string with dates + rooms_available = [] + + check_in = Date.parse(check_in) + check_out = Date.parse(check_out) + + if check_in > check_out + raise ArgumentError.new("Invalid date range") + end + + @reservation_collection.each do |entry| + # binding.pry + if check_in < entry.date_range.check_in && check_out <= entry.date_range.check_in + rooms_available << entry.room_num + elsif check_in >= entry.date_range.check_out && check_out > entry.date_range.check_out + rooms_available << entry.room_num + else + false + end + end + return rooms_available.uniq + end #room_availability + end #class @@ -58,4 +82,4 @@ def date_list_of_reservations(date) @bb_hotel = Hotel::Hotel.new(20, 200) @bb_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) @bb_hotel.make_reservation('sept 7 2017', 'sept 11 2017', 3) -p @bb_hotel.date_list_of_reservations('sept 9 2017') +p @bb_hotel.room_availability('sept 6 2017', 'sept 8 2017').class From 9bbc3fae06b8d6c692973c2929b86c1a6633a731 Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Sat, 9 Sep 2017 14:10:27 -0700 Subject: [PATCH 10/18] add sort and uniq method call to room availaibility array --- lib/hotel.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 37fa95dc6..2a2becb53 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -66,7 +66,7 @@ def room_availability(check_in, check_out) false end end - return rooms_available.uniq + return rooms_available.uniq.sort! end #room_availability @@ -82,4 +82,5 @@ def room_availability(check_in, check_out) @bb_hotel = Hotel::Hotel.new(20, 200) @bb_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) @bb_hotel.make_reservation('sept 7 2017', 'sept 11 2017', 3) -p @bb_hotel.room_availability('sept 6 2017', 'sept 8 2017').class +@bb_hotel.make_reservation('sept 6 2017', 'sept 7 2017', 3) +p @bb_hotel.room_availability('sept 5 2017', 'sept 6 2017') From 9e33f2bd0ff3dba1e639bd203cfcc98cdd13ba36 Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Sat, 9 Sep 2017 16:53:32 -0700 Subject: [PATCH 11/18] availability functionality with passing tests - draft 2 --- lib/hotel.rb | 68 ++++++++++++++++++++++++++------------------- lib/reservation.rb | 4 +++ specs/hotel_spec.rb | 36 ++++++++++++++++++++---- 3 files changed, 74 insertions(+), 34 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 2a2becb53..ab6c9d15e 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -5,14 +5,14 @@ module Hotel class Hotel - attr_reader :list_of_rooms, :price, :reservation_collection, :reservation_made + attr_reader :rooms, :price, :reservation_collection, :reservation_made def initialize(num_of_rooms, price) - @list_of_rooms = [] + @rooms = [] room_num = 0 num_of_rooms.times do |room| room_num += 1 - @list_of_rooms << room_num + @rooms << room_num end #loop @price = price @@ -31,15 +31,15 @@ def date_list_of_reservations(date) date = Date.parse(date) @reservation_collection.each do |entry| # binding.pry - if entry.date_range.check_in <= date && entry.date_range.check_out >= date - date_list << [entry.room_num, entry.date_range.check_in.to_s, entry.date_range.check_out.to_s] + if entry.check_in <= date && entry.check_out >= date + date_list << [entry.room_num, entry.check_in.to_s, entry.check_out.to_s] end end return date_list end #def # def list_of_rooms - # @list_of_rooms.each do |room| + # @rooms.each do |room| # puts "Room #{room}" # end # end #list_of_rooms @@ -47,8 +47,9 @@ def date_list_of_reservations(date) def room_availability(check_in, check_out) #can be string with dates - rooms_available = [] + rooms_available = @rooms.clone + # [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] check_in = Date.parse(check_in) check_out = Date.parse(check_out) @@ -57,30 +58,41 @@ def room_availability(check_in, check_out) end @reservation_collection.each do |entry| - # binding.pry - if check_in < entry.date_range.check_in && check_out <= entry.date_range.check_in - rooms_available << entry.room_num - elsif check_in >= entry.date_range.check_out && check_out > entry.date_range.check_out - rooms_available << entry.room_num - else - false + if check_in < entry.check_in && check_in < entry.check_out && check_out < entry.check_out && check_out > entry.check_in + rooms_available.delete(entry.room_num) + elsif check_in > entry.check_in && check_in < entry.check_out && check_out < entry.check_out && check_out > entry.check_in + rooms_available.delete(entry.room_num) + elsif check_in > entry.check_in && check_in < entry.check_out && check_out == entry.check_out && check_out > entry.check_in + rooms_available.delete(entry.room_num) + elsif check_in < entry.check_in && check_in < entry.check_out && check_out > entry.check_in && check_out == entry.check_out + rooms_available.delete(entry.room_num) + elsif check_in > entry.check_in && check_in < entry.check_out && check_out > entry.check_out + rooms_available.delete(entry.room_num) + elsif check_in == entry.check_in && check_in < entry.check_out && check_out > entry.check_in && check_out > entry.check_in + rooms_available.delete(entry.room_num) end end - return rooms_available.uniq.sort! - end #room_availability - - + return rooms_available + end #room_availability end #class - end #module -# my_hotel = Hotel::Hotel.new(20, 200) -# my_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) -# puts my_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) -# puts my_hotel.reservation.room_num.must_equal 4 -@bb_hotel = Hotel::Hotel.new(20, 200) -@bb_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) -@bb_hotel.make_reservation('sept 7 2017', 'sept 11 2017', 3) -@bb_hotel.make_reservation('sept 6 2017', 'sept 7 2017', 3) -p @bb_hotel.room_availability('sept 5 2017', 'sept 6 2017') +### second round of logic ### does not work because it will list rooms that are available for a given date range and not couple if the room is taken for another date + + +# if check_in == entry.check_in && check_in < entry.check_out && check_out > entry.check_in && check_out < entry.check_out +# false +# binding.pry +# +# elsif check_in< entry.check_in && check_out == entry.check_in && check_in < entry.check_out +# rooms_available << entry.room_num +# # elsif check_in < entry.check_in && check_in < entry.check_out && check_out == entry.check_in +# # rooms_available << entry.room_num +# elsif check_in == entry.check_out && check_out > entry.check_out +# rooms_available << entry.room_num +# elsif check_in > entry.check_out +# rooms_available << entry.room_num +# # elsif check_in < entry.check_in && check_out < entry.check_in && check_in < entry.check_out +# # rooms_available << entry.room_num +# end diff --git a/lib/reservation.rb b/lib/reservation.rb index 65d5d91a6..1aebe008e 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -12,6 +12,10 @@ def initialize(check_in, check_out, room_num, cost = 200) @reservation_array = [] @date_range = DateRange.new(check_in, check_out) + @check_in = @date_range.check_in + @check_out = @date_range.check_out + + @reservation_array << @date_range @room_num = room_num diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index dac630ce2..f9a396b8e 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -9,11 +9,11 @@ end it "Can create an array of rooms" do - Hotel::Hotel.new(20, 200).list_of_rooms.length.must_equal 20 + Hotel::Hotel.new(20, 200).rooms.length.must_equal 20 end it "Can call the array of rooms" do - Hotel::Hotel.new(20,200).list_of_rooms.must_equal [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18, 19, 20] + Hotel::Hotel.new(20,200).rooms.must_equal [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18, 19, 20] end it "Can call on price of rooms" do @@ -29,7 +29,6 @@ before do @bb_hotel = Hotel::Hotel.new(20, 200) @bb_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) - end it "can be instantiated" do @@ -41,7 +40,6 @@ # res = @my_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) @bb_hotel.reservation_made.room_num.must_equal 4 end - end describe "#list of reservations for a specific date" do @@ -49,7 +47,6 @@ @bb_hotel = Hotel::Hotel.new(20, 200) @bb_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) @bb_hotel.make_reservation('sept 7 2017', 'sept 9 2017', 3) - end it "Returns an array of reservations for that date" do @@ -57,4 +54,31 @@ @bb_hotel.date_list_of_reservations('sept 9 2017').length.must_equal 2 end end -end #describe + + describe "#room availability" do + before do + @hotel = Hotel::Hotel.new(4, 200) + @hotel.make_reservation('sept 3 2017', 'sept 5 2017', 1) + @hotel.make_reservation('sept 5 2017', 'sept 7 2017', 1) + @hotel.make_reservation('sept 2 2017', 'sept 4 2017', 2) + @hotel.make_reservation('sept 6 2017', 'sept 8 2017', 2) + @hotel.make_reservation('sept 3 2017', 'sept 5 2017', 3) + @hotel.make_reservation('sept 2 2017', 'sept 3 2017', 3) + end + + it "Returns an array of available rooms" do + @hotel.room_availability('sept 1 2017', 'sept 4 2017').must_be_instance_of Array + end + + it "Returns the room numbers available for a certain date range" do + @hotel.room_availability('sept 1 2017', 'sept 3 2017').must_equal [1 ,4] + @hotel.room_availability('sept 5 2017', 'sept 6 2017').must_equal [2,3,4] + @hotel.room_availability('sept 7 2017', 'sept 8 2017').must_equal [1,3,4] + end + + it "Returns an ArgumentError if wrong date range entered" do + proc {@hotel.room_availability('sept 4 2017', 'sept 3 2017')}.must_raise ArgumentError + end + end + + end #describe From f558bd9de7eb56ddb76b256619cde436b66b8eec Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Sun, 10 Sep 2017 11:20:37 -0700 Subject: [PATCH 12/18] wave 2 complete with passing tests - may need more scrutinizing tests --- lib/date_range.rb | 1 - lib/hotel.rb | 15 +++++++++------ lib/reservation.rb | 3 +-- specs/hotel_spec.rb | 9 ++++++--- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index b6f840746..de757a39e 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -1,4 +1,3 @@ -require 'pry' module Hotel diff --git a/lib/hotel.rb b/lib/hotel.rb index ab6c9d15e..8cc4d2cec 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,4 +1,3 @@ -require 'pry' require_relative 'reservation' module Hotel @@ -20,10 +19,14 @@ def initialize(num_of_rooms, price) end #initialize def make_reservation(check_in, check_out, room_num) - @reservation_made = Reservation.new(check_in, check_out, room_num) - # binding.pry - - @reservation_collection << @reservation_made + if room_availability(check_in, check_out).include?(room_num) + puts "Reservation made" + @reservation_made = Reservation.new(check_in, check_out, room_num) + @reservation_collection << @reservation_made + else + raise ArgumentError.new("It appears the room you requested is booked during that date range") + end + # @reservation_collection << @reservation_made end def date_list_of_reservations(date) @@ -73,7 +76,7 @@ def room_availability(check_in, check_out) end end return rooms_available - end #room_availability + end #room_availability end #class end #module diff --git a/lib/reservation.rb b/lib/reservation.rb index 1aebe008e..35948bd10 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,6 +1,5 @@ require_relative 'date_range'#take note this needs to be included at the top -require 'pry' -require 'Date' +# require 'Date' module Hotel diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index f9a396b8e..d6570b118 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -27,7 +27,7 @@ describe "#make reservation" do before do - @bb_hotel = Hotel::Hotel.new(20, 200) + @bb_hotel = Hotel::Hotel.new(4, 200) @bb_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) end @@ -37,9 +37,12 @@ end it "Can call on class reservation methods" do - # res = @my_hotel.make_reservation('sept 8 2017', 'sept 10 2017', 4) @bb_hotel.reservation_made.room_num.must_equal 4 end + + it "Can return an argument error if room is not available for that date range" do + proc { @bb_hotel.make_reservation('sept 8 2017', 'sept 9 2017', 4)}.must_raise ArgumentError + end ####NOTE##### Not sure how to create a test to check if there is no problem with the code end describe "#list of reservations for a specific date" do @@ -81,4 +84,4 @@ end end - end #describe +end #describe From 23c7790db67914543f559d5bc0c3ae56007fae2c Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Sun, 10 Sep 2017 15:06:23 -0700 Subject: [PATCH 13/18] add block and block spec and initial framework of block class and interaction with hotel class --- lib/block.rb | 68 +++++++++++++++++++++++++++++++++++++++++++++ lib/hotel.rb | 39 +++++++++++++++++++++----- lib/reservation.rb | 8 ------ specs/block_spec.rb | 27 ++++++++++++++++++ 4 files changed, 127 insertions(+), 15 deletions(-) create mode 100644 lib/block.rb create mode 100644 specs/block_spec.rb diff --git a/lib/block.rb b/lib/block.rb new file mode 100644 index 000000000..13a80f8c7 --- /dev/null +++ b/lib/block.rb @@ -0,0 +1,68 @@ +require_relative 'date_range' +require_relative 'reservation' +require_relative 'hotel' + +module Hotel + + class BlockRoom 0 + + + + + # if Reservation.room_availability(check_in, check_out).length >= num_of_rooms + # @rooms_in_block << room_availability(check_in, check_out).pop(num_of_rooms) + # @status_of_rooms = Array.new(num_of_rooms, nil) + # else + # return raise ArgumentError.new("There are not enough rooms available for that date") + # end + + + # @status = status + # @reservation_array << @status + + # #####NOTE##### Trying to create hash of rooms in block based on their availability#### + # @rooms_status = rooms_in_block.zip(@status_of_rooms) + # + # ###or### + # rooms_availability_in_block_hash = {} + # @rooms_in_block.each_with_index {|key, index| rooms_availability_in_block_hash[key] = @status_of_rooms[index]} + # hash = {} + # keys.each_with_index { |key, index| hash[key] = values[index] } + end #initialize + + def check_if_block_has_available_rooms + end + + # ability to reserve a room within a block of rooms + #needs to match the date range of the block + def reserve_room_in_block_based_on_date(check_in, check_out, num_of_rooms) + #need to confirm there is availability + #need to match the range in the block + end + + #not a requirement, but could be a nice way to search for something + def reserve_room_in_block_based_on_client(check_in, check_out, client) + end + + + end #class +end#module diff --git a/lib/hotel.rb b/lib/hotel.rb index 8cc4d2cec..48aa4643d 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,10 +1,11 @@ require_relative 'reservation' +require_relative 'block' module Hotel class Hotel - attr_reader :rooms, :price, :reservation_collection, :reservation_made + attr_reader :rooms, :price, :reservation_collection, :block_reservation_collection, :reservation_made def initialize(num_of_rooms, price) @rooms = [] @@ -16,6 +17,7 @@ def initialize(num_of_rooms, price) @price = price @reservation_collection = [] + @block_reservation_collection = [] end #initialize def make_reservation(check_in, check_out, room_num) @@ -29,6 +31,18 @@ def make_reservation(check_in, check_out, room_num) # @reservation_collection << @reservation_made end + + def make_block_reservation(check_in, check_out, num_of_rooms) + if room_availability(check_in, check_out).length >= num_of_rooms + puts "we can create a block reservation" + @block_reservation = Block.new(check_in, check_out, num_of_rooms, client, discount, client, cost) + else + puts "appears we can't block rooms for you at this point" + end + end + + + def date_list_of_reservations(date) date_list = [] date = Date.parse(date) @@ -41,12 +55,6 @@ def date_list_of_reservations(date) return date_list end #def - # def list_of_rooms - # @rooms.each do |room| - # puts "Room #{room}" - # end - # end #list_of_rooms - # not needed for this more abstract hotel class def room_availability(check_in, check_out) #can be string with dates @@ -75,8 +83,25 @@ def room_availability(check_in, check_out) rooms_available.delete(entry.room_num) end end + + @block_reservation_collection.each do |entry| + if check_in < entry.check_in && check_in < entry.check_out && check_out < entry.check_out && check_out > entry.check_in + rooms_available.delete(entry.room_num) + elsif check_in > entry.check_in && check_in < entry.check_out && check_out < entry.check_out && check_out > entry.check_in + rooms_available.delete(entry.room_num) + elsif check_in > entry.check_in && check_in < entry.check_out && check_out == entry.check_out && check_out > entry.check_in + rooms_available.delete(entry.room_num) + elsif check_in < entry.check_in && check_in < entry.check_out && check_out > entry.check_in && check_out == entry.check_out + rooms_available.delete(entry.room_num) + elsif check_in > entry.check_in && check_in < entry.check_out && check_out > entry.check_out + rooms_available.delete(entry.room_num) + elsif check_in == entry.check_in && check_in < entry.check_out && check_out > entry.check_in && check_out > entry.check_in + rooms_available.delete(entry.room_num) + end + end return rooms_available end #room_availability + end #class end #module diff --git a/lib/reservation.rb b/lib/reservation.rb index 35948bd10..9dfe1aee9 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -22,9 +22,6 @@ def initialize(check_in, check_out, room_num, cost = 200) @cost = cost @reservation_array << @cost - - - end #initialize def total_cost @@ -33,9 +30,4 @@ def total_cost end end #reservation - - end #module - -# hotel = Hotel::Reservation.new('sept 9 2016', 'sept 9 2017', 18) -# puts hotel.date_range.check_out diff --git a/specs/block_spec.rb b/specs/block_spec.rb new file mode 100644 index 000000000..8b017928d --- /dev/null +++ b/specs/block_spec.rb @@ -0,0 +1,27 @@ +require_relative 'spec_helper' + +describe "Block child class" do + +describe "initialization" do + before do + @block = Hotel::BlockRoom.new('sept 1 2017', 'sept 2 2017', 3, "Fernandez", 10) + end + + it "Can create an instance of block" do + @block.must_be_instance_of Hotel::BlockRoom + end + + it "Can call methods regarding instance methods created" do + @block.reservation_array.must_be_instance_of Array + @block.num_of_rooms.must_equal 3 + @block.discount.must_equal 10 + @block.check_in.must_be_instance_of Date + @block.check_out.must_be_instance_of Date + @block.collection_of_rooms.must_be_instance_of Array + @block.cost.must_equal 200 + end + + +end + +end #block describe From fff14fd0ab5c8c57efac453ed3430a0abaf8aa32 Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Sun, 10 Sep 2017 15:17:52 -0700 Subject: [PATCH 14/18] Create two arrays - booked and available within Blockroom --- lib/block.rb | 9 ++++++++- lib/hotel.rb | 2 ++ specs/block_spec.rb | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/block.rb b/lib/block.rb index 13a80f8c7..6dc42294c 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -6,7 +6,7 @@ module Hotel class BlockRoom= num_of_rooms puts "we can create a block reservation" @block_reservation = Block.new(check_in, check_out, num_of_rooms, client, discount, client, cost) + @num_of_rooms << rooms_available.pop(num_of_rooms) else puts "appears we can't block rooms for you at this point" end @@ -84,6 +85,7 @@ def room_availability(check_in, check_out) end end +####NOTE##### need to relook at logic @block_reservation_collection.each do |entry| if check_in < entry.check_in && check_in < entry.check_out && check_out < entry.check_out && check_out > entry.check_in rooms_available.delete(entry.room_num) diff --git a/specs/block_spec.rb b/specs/block_spec.rb index 8b017928d..29f35f9af 100644 --- a/specs/block_spec.rb +++ b/specs/block_spec.rb @@ -19,6 +19,8 @@ @block.check_out.must_be_instance_of Date @block.collection_of_rooms.must_be_instance_of Array @block.cost.must_equal 200 + @block.booked_rooms.must_be_instance_of Array + @block.available_rooms.must_be_instance_of Array end From c3f3211ab440736070adc0b301476ef0505ba93d Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Sun, 10 Sep 2017 16:26:11 -0700 Subject: [PATCH 15/18] Passing make block reservation method --- lib/block.rb | 53 +++++++------------------------ lib/hotel.rb | 77 ++++++++++++++++++++++++++++++++++++++------- specs/block_spec.rb | 51 +++++++++++++++++++----------- specs/hotel_spec.rb | 26 ++++++++++++++- 4 files changed, 134 insertions(+), 73 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index 6dc42294c..cdd912077 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -6,7 +6,9 @@ module Hotel class BlockRoom 0 - - - - - # if Reservation.room_availability(check_in, check_out).length >= num_of_rooms - # @rooms_in_block << room_availability(check_in, check_out).pop(num_of_rooms) - # @status_of_rooms = Array.new(num_of_rooms, nil) - # else - # return raise ArgumentError.new("There are not enough rooms available for that date") - # end - - - # @status = status - # @reservation_array << @status - - # #####NOTE##### Trying to create hash of rooms in block based on their availability#### - # @rooms_status = rooms_in_block.zip(@status_of_rooms) - # - # ###or### - # rooms_availability_in_block_hash = {} - # @rooms_in_block.each_with_index {|key, index| rooms_availability_in_block_hash[key] = @status_of_rooms[index]} - # hash = {} - # keys.each_with_index { |key, index| hash[key] = values[index] } end #initialize def check_if_block_has_available_rooms + if @available_rooms.length >= 1 + return true + else + return raise ArgumentError.new("It appears there are no available rooms in block") + end end - # ability to reserve a room within a block of rooms - #needs to match the date range of the block - def reserve_room_in_block_based_on_date(check_in, check_out, num_of_rooms) - #need to confirm there is availability - #need to match the range in the block - end - - #not a requirement, but could be a nice way to search for something - def reserve_room_in_block_based_on_client(check_in, check_out, client) - end - - end #class end#module diff --git a/lib/hotel.rb b/lib/hotel.rb index 05b7ad69c..146342e1d 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,5 +1,6 @@ require_relative 'reservation' require_relative 'block' +# require 'pry' module Hotel @@ -33,16 +34,34 @@ def make_reservation(check_in, check_out, room_num) def make_block_reservation(check_in, check_out, num_of_rooms) - if room_availability(check_in, check_out).length >= num_of_rooms + available_rooms = room_availability(check_in, check_out) + if available_rooms.length >= num_of_rooms puts "we can create a block reservation" - @block_reservation = Block.new(check_in, check_out, num_of_rooms, client, discount, client, cost) - @num_of_rooms << rooms_available.pop(num_of_rooms) + @block_reservation = BlockRoom.new(check_in, check_out, num_of_rooms) + @block_reservation.block_of_rooms << available_rooms.pop(num_of_rooms) + return @block_reservation.block_of_rooms else - puts "appears we can't block rooms for you at this point" + return raise ArgumentError.new("We do not have enough rooms to reserve a block") end end + # ability to reserve a room within a block of rooms + #needs to match the date range of the block + def reserve_room_in_block_based_on_date(check_in, check_out, num_of_rooms) + check_in = Date.parse(check_in) + check_out = Date.parse(check_out) + + @block_reservation_collection.each do |entry| + if check_in == entry.check_in && check_out == entry.check_out + if entry.available_rooms.length >= num_of_rooms + num_of_rooms.times do + @booked_rooms << @available_rooms.pop + end + end + end + end + end def date_list_of_reservations(date) date_list = [] @@ -56,7 +75,6 @@ def date_list_of_reservations(date) return date_list end #def - def room_availability(check_in, check_out) #can be string with dates rooms_available = @rooms.clone @@ -85,20 +103,31 @@ def room_availability(check_in, check_out) end end -####NOTE##### need to relook at logic @block_reservation_collection.each do |entry| if check_in < entry.check_in && check_in < entry.check_out && check_out < entry.check_out && check_out > entry.check_in - rooms_available.delete(entry.room_num) + entry.block_of_rooms.each do |room| + rooms_available.delete(room) + end elsif check_in > entry.check_in && check_in < entry.check_out && check_out < entry.check_out && check_out > entry.check_in - rooms_available.delete(entry.room_num) + entry.block_of_rooms.each do |room| + rooms_available.delete(room) + end elsif check_in > entry.check_in && check_in < entry.check_out && check_out == entry.check_out && check_out > entry.check_in - rooms_available.delete(entry.room_num) + entry.block_of_rooms.each do |room| + rooms_available.delete(room) + end elsif check_in < entry.check_in && check_in < entry.check_out && check_out > entry.check_in && check_out == entry.check_out - rooms_available.delete(entry.room_num) + entry.block_of_rooms.each do |room| + rooms_available.delete(room) + end elsif check_in > entry.check_in && check_in < entry.check_out && check_out > entry.check_out - rooms_available.delete(entry.room_num) + entry.block_of_rooms.each do |room| + rooms_available.delete(room) + end elsif check_in == entry.check_in && check_in < entry.check_out && check_out > entry.check_in && check_out > entry.check_in - rooms_available.delete(entry.room_num) + entry.block_of_rooms.each do |room| + rooms_available.delete(room) + end end end return rooms_available @@ -108,6 +137,30 @@ def room_availability(check_in, check_out) end #module +# @hotel = Hotel::Hotel.new(6, 200) +# @hotel.make_reservation('sept 3 2017', 'sept 5 2017', 1) +# @hotel.make_reservation('sept 5 2017', 'sept 7 2017', 1) +# @hotel.make_reservation('sept 2 2017', 'sept 4 2017', 2) +# @hotel.make_reservation('sept 6 2017', 'sept 8 2017', 2) +# @hotel.make_reservation('sept 3 2017', 'sept 5 2017', 3) +# @hotel.make_reservation('sept 2 2017', 'sept 3 2017', 3) +# +# @hotel.make_block_reservation('sept 1 2017', 'sept 4 2017', 3).must_equal [4,5,6] + + + + + + + + + + + + + + + ### second round of logic ### does not work because it will list rooms that are available for a given date range and not couple if the room is taken for another date diff --git a/specs/block_spec.rb b/specs/block_spec.rb index 29f35f9af..448a9816e 100644 --- a/specs/block_spec.rb +++ b/specs/block_spec.rb @@ -2,28 +2,43 @@ describe "Block child class" do -describe "initialization" do - before do - @block = Hotel::BlockRoom.new('sept 1 2017', 'sept 2 2017', 3, "Fernandez", 10) - end + describe "initialization" do + before do + @block = Hotel::BlockRoom.new('sept 1 2017', 'sept 2 2017', 3, "Fernandez", 10) + end - it "Can create an instance of block" do - @block.must_be_instance_of Hotel::BlockRoom - end + it "Can create an instance of block" do + @block.must_be_instance_of Hotel::BlockRoom + end + + it "Can call methods regarding instance methods created" do + @block.reservation_array.must_be_instance_of Array + @block.num_of_rooms.must_equal 3 + @block.discount.must_equal 10 + @block.check_in.must_be_instance_of Date + @block.check_out.must_be_instance_of Date + @block.block_of_rooms.must_be_instance_of Array + @block.cost.must_equal 200 + @block.booked_rooms.must_be_instance_of Array + @block.available_rooms.must_be_instance_of Array + end - it "Can call methods regarding instance methods created" do - @block.reservation_array.must_be_instance_of Array - @block.num_of_rooms.must_equal 3 - @block.discount.must_equal 10 - @block.check_in.must_be_instance_of Date - @block.check_out.must_be_instance_of Date - @block.collection_of_rooms.must_be_instance_of Array - @block.cost.must_equal 200 - @block.booked_rooms.must_be_instance_of Array - @block.available_rooms.must_be_instance_of Array end + describe "check if block has rooms available" do + before do + @block = Hotel::BlockRoom.new('sept 1 2017', 'sept 2 2017', 3, "Fernandez", 10) + end -end + it "Can raise an argument if there aren't rooms available" do + @block.available_rooms = [] + proc {@block.check_if_block_has_available_rooms}.must_raise ArgumentError + end + + it "Can return an array of available rooms" do + @block.available_rooms = [2,3,4] + @block.check_if_block_has_available_rooms.must_equal true + end + end end #block describe diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index d6570b118..e81dcf7c4 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -42,7 +42,7 @@ it "Can return an argument error if room is not available for that date range" do proc { @bb_hotel.make_reservation('sept 8 2017', 'sept 9 2017', 4)}.must_raise ArgumentError - end ####NOTE##### Not sure how to create a test to check if there is no problem with the code + end ####NOTE##### Not sure how to create a test to check if there is no problem with the code end describe "#list of reservations for a specific date" do @@ -84,4 +84,28 @@ end end + describe "make block reservation method" do + before do + @hotel = Hotel::Hotel.new(6, 200) + @hotel.make_reservation('sept 3 2017', 'sept 5 2017', 1) + @hotel.make_reservation('sept 5 2017', 'sept 7 2017', 1) + @hotel.make_reservation('sept 2 2017', 'sept 4 2017', 2) + @hotel.make_reservation('sept 6 2017', 'sept 8 2017', 2) + @hotel.make_reservation('sept 3 2017', 'sept 5 2017', 3) + @hotel.make_reservation('sept 2 2017', 'sept 3 2017', 3) + end + + it "Can create an entry in the block reservations array" do + @hotel.make_block_reservation('sept 1 2017', 'sept 4 2017', 3).must_equal [[4,5,6]] + end + + end + + describe "making room reservation in a block" do + + it "Can determine if a block has available rooms and move them to booked " do + end + + end #describe #block room reservation + end #describe From a49f9f7befac3651ba648cf97393ec6e19bf198a Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Sun, 10 Sep 2017 16:59:33 -0700 Subject: [PATCH 16/18] Can book rooms in a given block --- lib/block.rb | 2 +- lib/hotel.rb | 38 ++++++++++++++++++++++++-------------- specs/hotel_spec.rb | 16 ++++++++++++++++ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index cdd912077..2d2da7f09 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -4,7 +4,7 @@ module Hotel - class BlockRoom= num_of_rooms + if entry.available_rooms[0].length >= num_of_rooms num_of_rooms.times do - @booked_rooms << @available_rooms.pop + entry.booked_rooms << entry.available_rooms[0].pop end + return entry.booked_rooms end end end end + # end + + # end + # return entry.booked_rooms + + # end + # end + # end def date_list_of_reservations(date) date_list = [] @@ -137,15 +146,16 @@ def room_availability(check_in, check_out) end #module -# @hotel = Hotel::Hotel.new(6, 200) -# @hotel.make_reservation('sept 3 2017', 'sept 5 2017', 1) -# @hotel.make_reservation('sept 5 2017', 'sept 7 2017', 1) -# @hotel.make_reservation('sept 2 2017', 'sept 4 2017', 2) -# @hotel.make_reservation('sept 6 2017', 'sept 8 2017', 2) -# @hotel.make_reservation('sept 3 2017', 'sept 5 2017', 3) -# @hotel.make_reservation('sept 2 2017', 'sept 3 2017', 3) +# hotel = Hotel::Hotel.new(6, 200) +# hotel.make_reservation('sept 3 2017', 'sept 5 2017', 1) +# hotel.make_reservation('sept 5 2017', 'sept 7 2017', 1) +# hotel.make_reservation('sept 2 2017', 'sept 4 2017', 2) +# hotel.make_reservation('sept 6 2017', 'sept 8 2017', 2) +# hotel.make_reservation('sept 3 2017', 'sept 5 2017', 3) +# hotel.make_reservation('sept 2 2017', 'sept 3 2017', 3) # -# @hotel.make_block_reservation('sept 1 2017', 'sept 4 2017', 3).must_equal [4,5,6] +# hotel.make_block_reservation('sept 1 2017', 'sept 4 2017', 3) + diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index e81dcf7c4..71eae37b4 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -99,11 +99,27 @@ @hotel.make_block_reservation('sept 1 2017', 'sept 4 2017', 3).must_equal [[4,5,6]] end + it "Returns an error message if not enough rooms are availanle to book" do + proc {@hotel.make_block_reservation('sept 1 2017', 'sept 4 2017', 4)}.must_raise ArgumentError + end + end describe "making room reservation in a block" do + before do + @hotel = Hotel::Hotel.new(6, 200) + @hotel.make_reservation('sept 3 2017', 'sept 5 2017', 1) + @hotel.make_reservation('sept 5 2017', 'sept 7 2017', 1) + @hotel.make_reservation('sept 2 2017', 'sept 4 2017', 2) + @hotel.make_reservation('sept 6 2017', 'sept 8 2017', 2) + @hotel.make_reservation('sept 3 2017', 'sept 5 2017', 3) + @hotel.make_reservation('sept 2 2017', 'sept 3 2017', 3) + @hotel.make_block_reservation('sept 1 2017', 'sept 4 2017', 3) + + end it "Can determine if a block has available rooms and move them to booked " do + @hotel.reserve_room_in_block('sept 1 2017', 'sept 4 2017', 2).must_equal [6,5] end end #describe #block room reservation From 3489cb03174366aa945e6969e7fadea03c9e90a1 Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Sun, 10 Sep 2017 17:05:03 -0700 Subject: [PATCH 17/18] Can check if block has any available rooms --- lib/hotel.rb | 18 ++++++++++++------ specs/hotel_spec.rb | 7 ++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index bb63ad26a..19c4c9246 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -63,14 +63,20 @@ def reserve_room_in_block(check_in, check_out, num_of_rooms) end end end - # end - # end - # return entry.booked_rooms + def blocked_rooms_availability(check_in, check_out) + check_in = Date.parse(check_in) + check_out = Date.parse(check_out) - # end - # end - # end + @block_reservation_collection.each do |entry| + if check_in == entry.check_in && check_out == entry.check_out + if entry.available_rooms[0].length >= 0 + return true + else false + end + end + end + end def date_list_of_reservations(date) date_list = [] diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 71eae37b4..522924587 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -105,7 +105,7 @@ end - describe "making room reservation in a block" do + describe "checking room availability and making room reservation in a block" do before do @hotel = Hotel::Hotel.new(6, 200) @hotel.make_reservation('sept 3 2017', 'sept 5 2017', 1) @@ -118,6 +118,11 @@ end + it "can let you know if a block has rooms available" do + @hotel.blocked_rooms_availability('sept 1 2017', 'sept 4 2017').must_equal true + + end + it "Can determine if a block has available rooms and move them to booked " do @hotel.reserve_room_in_block('sept 1 2017', 'sept 4 2017', 2).must_equal [6,5] end From 729c650816d16c4cdadea5338fadf25db63288d6 Mon Sep 17 00:00:00 2001 From: Bianca M Fernandez Date: Sun, 10 Sep 2017 17:53:56 -0700 Subject: [PATCH 18/18] Correction to availability logic to go into actual room array within each block of rooms --- lib/block.rb | 4 ++++ lib/hotel.rb | 32 ++++++++++++-------------------- specs/block_spec.rb | 4 ++++ specs/hotel_spec.rb | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index 2d2da7f09..73c38e8cb 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -17,6 +17,10 @@ def initialize(check_in, check_out, num_of_rooms = 5, client = nil, discount = 1 @discount = discount @reservation_array << @discount + if num_of_rooms > 5 + return raise ArgumentError.new("You cannot reserve a block with more than 5 rooms") + end + @num_of_rooms = num_of_rooms @reservation_array << @num_of_rooms diff --git a/lib/hotel.rb b/lib/hotel.rb index 19c4c9246..f7f967693 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -35,11 +35,10 @@ def make_reservation(check_in, check_out, room_num) def make_block_reservation(check_in, check_out, num_of_rooms) available_rooms = room_availability(check_in, check_out) if available_rooms.length >= num_of_rooms - puts "we can create a block reservation" - @block_reservation = BlockRoom.new(check_in, check_out, num_of_rooms) - @block_reservation.block_of_rooms << available_rooms.pop(num_of_rooms) - @block_reservation_collection << @block_reservation - return @block_reservation.block_of_rooms + block_reservation = BlockRoom.new(check_in, check_out, num_of_rooms) + block_reservation.block_of_rooms << available_rooms.pop(num_of_rooms) + @block_reservation_collection << block_reservation + return block_reservation.block_of_rooms else return raise ArgumentError.new("We do not have enough rooms to reserve a block") end @@ -120,27 +119,27 @@ def room_availability(check_in, check_out) @block_reservation_collection.each do |entry| if check_in < entry.check_in && check_in < entry.check_out && check_out < entry.check_out && check_out > entry.check_in - entry.block_of_rooms.each do |room| + entry.block_of_rooms[0].each do |room| rooms_available.delete(room) end elsif check_in > entry.check_in && check_in < entry.check_out && check_out < entry.check_out && check_out > entry.check_in - entry.block_of_rooms.each do |room| + entry.block_of_rooms[0].each do |room| rooms_available.delete(room) end elsif check_in > entry.check_in && check_in < entry.check_out && check_out == entry.check_out && check_out > entry.check_in - entry.block_of_rooms.each do |room| + entry.block_of_rooms[0].each do |room| rooms_available.delete(room) end elsif check_in < entry.check_in && check_in < entry.check_out && check_out > entry.check_in && check_out == entry.check_out - entry.block_of_rooms.each do |room| + entry.block_of_rooms[0].each do |room| rooms_available.delete(room) end elsif check_in > entry.check_in && check_in < entry.check_out && check_out > entry.check_out - entry.block_of_rooms.each do |room| + entry.block_of_rooms[0].each do |room| rooms_available.delete(room) end elsif check_in == entry.check_in && check_in < entry.check_out && check_out > entry.check_in && check_out > entry.check_in - entry.block_of_rooms.each do |room| + entry.block_of_rooms[0].each do |room| rooms_available.delete(room) end end @@ -152,15 +151,8 @@ def room_availability(check_in, check_out) end #module -# hotel = Hotel::Hotel.new(6, 200) -# hotel.make_reservation('sept 3 2017', 'sept 5 2017', 1) -# hotel.make_reservation('sept 5 2017', 'sept 7 2017', 1) -# hotel.make_reservation('sept 2 2017', 'sept 4 2017', 2) -# hotel.make_reservation('sept 6 2017', 'sept 8 2017', 2) -# hotel.make_reservation('sept 3 2017', 'sept 5 2017', 3) -# hotel.make_reservation('sept 2 2017', 'sept 3 2017', 3) -# -# hotel.make_block_reservation('sept 1 2017', 'sept 4 2017', 3) + + diff --git a/specs/block_spec.rb b/specs/block_spec.rb index 448a9816e..b8fe7b273 100644 --- a/specs/block_spec.rb +++ b/specs/block_spec.rb @@ -23,6 +23,10 @@ @block.available_rooms.must_be_instance_of Array end + it "Will return error message if try to book more than 5 rooms in a block" do + proc {Hotel::BlockRoom.new('today', 'tomorrow', 6)}.must_raise ArgumentError + end + end describe "check if block has rooms available" do diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 522924587..0e45c0fdf 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -22,6 +22,8 @@ it "can call on collection of reservations array - will be empty" do Hotel::Hotel.new(20, 200).reservation_collection.must_be_instance_of Array + Hotel::Hotel.new(20, 200).block_reservation_collection.must_be_instance_of Array + end end #describe instantiate @@ -77,11 +79,20 @@ @hotel.room_availability('sept 1 2017', 'sept 3 2017').must_equal [1 ,4] @hotel.room_availability('sept 5 2017', 'sept 6 2017').must_equal [2,3,4] @hotel.room_availability('sept 7 2017', 'sept 8 2017').must_equal [1,3,4] + @hotel.make_block_reservation('sept 5 2017', 'sept 6 2017', 3) + @hotel.room_availability('sept 5 2017', 'sept 6 2017').must_equal [] end it "Returns an ArgumentError if wrong date range entered" do proc {@hotel.room_availability('sept 4 2017', 'sept 3 2017')}.must_raise ArgumentError end + + it "Does not let general public reserve rooms that are in a block" do + end + + it "does not let you overbook a room in a block if that room is being saved in another block" do + end + end describe "make block reservation method" do @@ -127,6 +138,10 @@ @hotel.reserve_room_in_block('sept 1 2017', 'sept 4 2017', 2).must_equal [6,5] end + it "Does not let general public book a room in a block" do + @hotel.room_availability('sept 1 2017', 'sept 4 2017').must_equal [] + end + end #describe #block room reservation end #describe