From cdcf55f0d3b0e1135702376b70c206e80c0b998c Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Mon, 5 Mar 2018 15:03:45 -0800 Subject: [PATCH 01/43] add reservation class and test methods --- lib/reservation.rb | 30 ++++++++++++++++++++++++++++++ specs/reservation_specs.rb | 31 +++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 lib/reservation.rb create mode 100644 specs/reservation_specs.rb diff --git a/lib/reservation.rb b/lib/reservation.rb new file mode 100644 index 000000000..4fd131de0 --- /dev/null +++ b/lib/reservation.rb @@ -0,0 +1,30 @@ +require 'time' + +module Hotel + class Reservation + attr_reader :start_date, :end_date + + def initialize(input) + + if input[:start_date] == nil || input[:end_date] == nil + raise ArgumentError.new("Date must be a date.") + end + + input[:start_date] = Time.parse(input[:start_date]) + input[:end_date] = Time.parse(input[:end_date]) + + if input[:start_date] >= input[:end_date] + raise ArgumentError.new("End date must be after start date.") + end + + @start_date = input[:start_date] + @end_date = input[:end_date] + + end + + def length + (@end_date - @start_date) / 86400 + end + + end +end diff --git a/specs/reservation_specs.rb b/specs/reservation_specs.rb new file mode 100644 index 000000000..89b7ee4ae --- /dev/null +++ b/specs/reservation_specs.rb @@ -0,0 +1,31 @@ +require_relative 'spec_helper' + +describe "Reservation class" do + describe "Initializer" do + it "is an instance of Reservation" do + reservation = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25"}) + reservation.must_be_kind_of Hotel::Reservation + end + + it "throws an argument error for a bad start date" do + proc{ Hotel::Reservation.new({start_date: nil, end_date: "2015-07-20" }) }.must_raise ArgumentError + end + + it "throws an argument error for a bad end date" do + proc{ Hotel::Reservation.new({start_date: "2015-07-20", end_date: nil }) }.must_raise ArgumentError + end + + it "throws an argument error when end date isn't after start date" do + proc{ Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-20" }) }.must_raise ArgumentError + proc{ Hotel::Reservation.new({start_date: "2015-07-21", end_date: "2015-07-20" }) }.must_raise ArgumentError + end + end + + describe "length method" do + it "calculates the number of nights for the hotel stay" do + @reservation = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25"}) + @reservation.length.must_equal 5 + end + end + + end From 8587c1fa5d49af901f3e9986753022965e696fef Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Mon, 5 Mar 2018 15:06:35 -0800 Subject: [PATCH 02/43] updated length method to ensure output is an integer --- lib/reservation.rb | 2 +- specs/reservation_specs.rb | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 4fd131de0..e208bb833 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -23,7 +23,7 @@ def initialize(input) end def length - (@end_date - @start_date) / 86400 + ((@end_date - @start_date) / 86400).to_i end end diff --git a/specs/reservation_specs.rb b/specs/reservation_specs.rb index 89b7ee4ae..0fc6a83d7 100644 --- a/specs/reservation_specs.rb +++ b/specs/reservation_specs.rb @@ -24,8 +24,9 @@ describe "length method" do it "calculates the number of nights for the hotel stay" do @reservation = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25"}) - @reservation.length.must_equal 5 - end + @reservation.length.must_equal 5 + @reservation.length.must_be_kind_of Integer end - end + +end From f5f634c9f2213671e25475e19bc576da4bf8023e Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Mon, 5 Mar 2018 15:37:51 -0800 Subject: [PATCH 03/43] created room class, method, and test file --- lib/room.rb | 16 ++++++++++++++++ specs/room_specs.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/room.rb create mode 100644 specs/room_specs.rb diff --git a/lib/room.rb b/lib/room.rb new file mode 100644 index 000000000..bf5a0fe1f --- /dev/null +++ b/lib/room.rb @@ -0,0 +1,16 @@ + +module Hotel + class Room + attr_reader :room, :cost + COST = 200 + + def initialize(input) + @room = input + end + + def price + @cost = COST + end + + end +end diff --git a/specs/room_specs.rb b/specs/room_specs.rb new file mode 100644 index 000000000..c3f400a93 --- /dev/null +++ b/specs/room_specs.rb @@ -0,0 +1,26 @@ +require_relative 'spec_helper' + +describe "Room class" do + + describe "Initializer" do + it "Can be created" do + room = Hotel::Room.new("unit_name") + room.must_be_instance_of Hotel::Room + end + + it "Is an instance of Room" do + room = Hotel::Room.new("unit_name") + room.class.must_equal Hotel::Room + end + + end + + describe "price method" do + it "returns price" do + room = Hotel::Room.new("unit_name") + room.price.must_equal 200 + room.price.must_be_kind_of Integer + end + end + +end From c547e7b674414c2a0e20fff457c1d35cc3662dfd Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Mon, 5 Mar 2018 15:38:18 -0800 Subject: [PATCH 04/43] create spec helper --- specs/spec_helper.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 specs/spec_helper.rb diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb new file mode 100644 index 000000000..e2c427827 --- /dev/null +++ b/specs/spec_helper.rb @@ -0,0 +1,12 @@ +require 'simplecov' +SimpleCov.start +require 'time' +require 'minitest' +require 'minitest/autorun' +require 'minitest/reporters' + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new + +require_relative '../lib/hotel_admin' +require_relative '../lib/reservation' +require_relative '../lib/room' From a3fdcdd9a5a3f8076b5680fa069f3a69b676072e Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Tue, 6 Mar 2018 18:20:58 -0800 Subject: [PATCH 05/43] created hotel_admin method and tests to return array of reservations for a date --- lib/hotel_admin.rb | 62 +++++++++++++++++++++++++++++++++++++++ specs/hotel_admin_spec.rb | 61 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 lib/hotel_admin.rb create mode 100644 specs/hotel_admin_spec.rb diff --git a/lib/hotel_admin.rb b/lib/hotel_admin.rb new file mode 100644 index 000000000..d50a72acc --- /dev/null +++ b/lib/hotel_admin.rb @@ -0,0 +1,62 @@ +require 'time' +require_relative 'reservation' +require_relative 'room' + +module Hotel + class HotelAdmin + attr_reader :rooms, :reservations, :unit, :reservation + + def initialize + @rooms = [] + @reservations = [] + end + + def load_rooms + room_arr = [] + [*1..20].each do |n| + room = Room.new(n) + # @unit = unit + room_arr << room + @rooms = room_arr + end + return @rooms #room_arr + end + + def add_reservation(reservation) + # new_reservation = (reservation) + # reservations_arr << new_reservation + @reservations << reservation + # @reservation = new_reservation + end + + def calc_reservations(room, reservation) + room.price * reservation.length + end + + def access_reservations(day) + days_reservations = [] + @reservations.each do |reservation| + if day.between?(reservation.start_date.strftime("%Y-%m-%d"),reservation.end_date.strftime("%Y-%m-%d")) + + days_reservations << reservation + end + end + return days_reservations + end + + + # def load_reservations + # reservations_arr = [] + # reservation = Hotel::Reservation.new + # input[:start_date] + # input[:end_date] + # reservations_arr << reservation + # return reservations_arr + # end + + # def load_reservations + # + # end + + end +end diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb new file mode 100644 index 000000000..077349a32 --- /dev/null +++ b/specs/hotel_admin_spec.rb @@ -0,0 +1,61 @@ +require_relative 'spec_helper' + +describe "HotelAdmin class" do + describe "Initializer" do + it "is an instance of TripDispatcher" do + hotel_admin = Hotel::HotelAdmin.new + hotel_admin.must_be_kind_of Hotel::HotelAdmin + end + + it "establishes the base data structures when instantiated" do + hotel_admin = Hotel::HotelAdmin.new + [:rooms, :reservations].each do |i| + hotel_admin.must_respond_to i + end + hotel_admin.rooms.must_be_kind_of Array + hotel_admin.reservations.must_be_kind_of Array + end + + end + + describe "calculates reservation cost" do + it "calculates the cost of a given reservation" do + hotel_admin = Hotel::HotelAdmin.new + room = Hotel::Room.new("unit_name") + reservation = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25", room_id: 1}) + hotel_admin.calc_reservations(room, reservation).must_equal 1000 + end + end + + describe "dates reservations method" do + # before do + # hotel_admin = Hotel::HotelAdmin.new + # end + + it "returns a list of reservations for a specific date" do + hotel_admin = Hotel::HotelAdmin.new + reservation_a = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25", room_id: 1}) + reservation_b = Hotel::Reservation.new({start_date: "2015-07-21", end_date: "2015-07-25", room_id: 2}) + hotel_admin.add_reservation(reservation_a) + hotel_admin.add_reservation(reservation_b) + hotel_admin.access_reservations("2015-07-20").must_equal [reservation_a] + hotel_admin.access_reservations("2015-07-22").must_equal [reservation_a, reservation_b] + end + + + + it "returns a list of rooms" do + + + end + + it "can reserve a room for a given date range" do + + end + + end + + + + +end From 45907e87ccca09db0d444b83ca1517382ef224ec Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Tue, 6 Mar 2018 18:21:40 -0800 Subject: [PATCH 06/43] updated filed names so they could be read by rake --- specs/reservation_spec.rb | 32 ++++++++++++++++++++++++++++++++ specs/room_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 specs/reservation_spec.rb create mode 100644 specs/room_spec.rb diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb new file mode 100644 index 000000000..0fc6a83d7 --- /dev/null +++ b/specs/reservation_spec.rb @@ -0,0 +1,32 @@ +require_relative 'spec_helper' + +describe "Reservation class" do + describe "Initializer" do + it "is an instance of Reservation" do + reservation = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25"}) + reservation.must_be_kind_of Hotel::Reservation + end + + it "throws an argument error for a bad start date" do + proc{ Hotel::Reservation.new({start_date: nil, end_date: "2015-07-20" }) }.must_raise ArgumentError + end + + it "throws an argument error for a bad end date" do + proc{ Hotel::Reservation.new({start_date: "2015-07-20", end_date: nil }) }.must_raise ArgumentError + end + + it "throws an argument error when end date isn't after start date" do + proc{ Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-20" }) }.must_raise ArgumentError + proc{ Hotel::Reservation.new({start_date: "2015-07-21", end_date: "2015-07-20" }) }.must_raise ArgumentError + end + end + + describe "length method" do + it "calculates the number of nights for the hotel stay" do + @reservation = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25"}) + @reservation.length.must_equal 5 + @reservation.length.must_be_kind_of Integer + end + end + +end diff --git a/specs/room_spec.rb b/specs/room_spec.rb new file mode 100644 index 000000000..c3f400a93 --- /dev/null +++ b/specs/room_spec.rb @@ -0,0 +1,26 @@ +require_relative 'spec_helper' + +describe "Room class" do + + describe "Initializer" do + it "Can be created" do + room = Hotel::Room.new("unit_name") + room.must_be_instance_of Hotel::Room + end + + it "Is an instance of Room" do + room = Hotel::Room.new("unit_name") + room.class.must_equal Hotel::Room + end + + end + + describe "price method" do + it "returns price" do + room = Hotel::Room.new("unit_name") + room.price.must_equal 200 + room.price.must_be_kind_of Integer + end + end + +end From f1e264e42d7da80aceae1e5a22be2c739da67ad3 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Tue, 6 Mar 2018 18:22:02 -0800 Subject: [PATCH 07/43] created Rakefile --- Rakefile | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Rakefile 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 From a7db22932e7c1c587af1f66d53511a7f9e2d0b6e Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Wed, 7 Mar 2018 09:41:17 -0800 Subject: [PATCH 08/43] changed name of local variage in initialize method in Room class --- lib/room.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index bf5a0fe1f..7f5af7f43 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -4,8 +4,8 @@ class Room attr_reader :room, :cost COST = 200 - def initialize(input) - @room = input + def initialize(room_num) + @room = room_num end def price From 4dd8d1629d8621b389cc2d54f111fde0791a4fe8 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Wed, 7 Mar 2018 09:43:40 -0800 Subject: [PATCH 09/43] deleted room_specs.rb and replaced it with room_spec.rb --- specs/room_specs.rb | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 specs/room_specs.rb diff --git a/specs/room_specs.rb b/specs/room_specs.rb deleted file mode 100644 index c3f400a93..000000000 --- a/specs/room_specs.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative 'spec_helper' - -describe "Room class" do - - describe "Initializer" do - it "Can be created" do - room = Hotel::Room.new("unit_name") - room.must_be_instance_of Hotel::Room - end - - it "Is an instance of Room" do - room = Hotel::Room.new("unit_name") - room.class.must_equal Hotel::Room - end - - end - - describe "price method" do - it "returns price" do - room = Hotel::Room.new("unit_name") - room.price.must_equal 200 - room.price.must_be_kind_of Integer - end - end - -end From f99f7652e1168fdc417592005292c082848d4ea7 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Wed, 7 Mar 2018 09:44:53 -0800 Subject: [PATCH 10/43] deleted reservation_specs.rb and replaced it with reservation_spec.rb so that it'd be uniform for rake --- specs/reservation_specs.rb | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 specs/reservation_specs.rb diff --git a/specs/reservation_specs.rb b/specs/reservation_specs.rb deleted file mode 100644 index 0fc6a83d7..000000000 --- a/specs/reservation_specs.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative 'spec_helper' - -describe "Reservation class" do - describe "Initializer" do - it "is an instance of Reservation" do - reservation = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25"}) - reservation.must_be_kind_of Hotel::Reservation - end - - it "throws an argument error for a bad start date" do - proc{ Hotel::Reservation.new({start_date: nil, end_date: "2015-07-20" }) }.must_raise ArgumentError - end - - it "throws an argument error for a bad end date" do - proc{ Hotel::Reservation.new({start_date: "2015-07-20", end_date: nil }) }.must_raise ArgumentError - end - - it "throws an argument error when end date isn't after start date" do - proc{ Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-20" }) }.must_raise ArgumentError - proc{ Hotel::Reservation.new({start_date: "2015-07-21", end_date: "2015-07-20" }) }.must_raise ArgumentError - end - end - - describe "length method" do - it "calculates the number of nights for the hotel stay" do - @reservation = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25"}) - @reservation.length.must_equal 5 - @reservation.length.must_be_kind_of Integer - end - end - -end From 509fef86d188dd703e91c0563785e6cf0602fbd7 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Wed, 7 Mar 2018 09:47:37 -0800 Subject: [PATCH 11/43] add room to initialize method in reservation class, add self method for start and end dates --- lib/reservation.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/reservation.rb b/lib/reservation.rb index e208bb833..25a9499f8 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -17,8 +17,11 @@ def initialize(input) raise ArgumentError.new("End date must be after start date.") end + #add room_id ArgumentError if necessary + @start_date = input[:start_date] @end_date = input[:end_date] + @room_id = input[:room_id] end @@ -26,5 +29,26 @@ def length ((@end_date - @start_date) / 86400).to_i end + # def puts_self + # puts Hotel::Reservation.new + # end + + def start_date + @start_date + end + + def end_date + @end_date + end + + #.strftime("%m/%d/%Y") + + # def self.all + # reservations_arr = [] + # @reservation + # reservations_arr << reservation + # return reservations_arr + # end + end end From 3821f9e343659d6e73970a8395f055d97f030702 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Thu, 8 Mar 2018 09:51:47 -0800 Subject: [PATCH 12/43] corrected method to access reservations for a certain day --- lib/hotel_admin.rb | 9 +++++---- specs/hotel_admin_spec.rb | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/hotel_admin.rb b/lib/hotel_admin.rb index d50a72acc..574564c7e 100644 --- a/lib/hotel_admin.rb +++ b/lib/hotel_admin.rb @@ -17,8 +17,8 @@ def load_rooms room = Room.new(n) # @unit = unit room_arr << room - @rooms = room_arr end + @rooms = room_arr return @rooms #room_arr end @@ -36,7 +36,9 @@ def calc_reservations(room, reservation) def access_reservations(day) days_reservations = [] @reservations.each do |reservation| - if day.between?(reservation.start_date.strftime("%Y-%m-%d"),reservation.end_date.strftime("%Y-%m-%d")) + checkin_date_loc = reservation.checkin_date.strftime("%Y-%m-%d") + checkout_date_loc = reservation.checkout_date.strftime("%Y-%m-%d") + if (checkin_date_loc...checkout_date_loc).include?(day) days_reservations << reservation end @@ -44,11 +46,10 @@ def access_reservations(day) return days_reservations end - # def load_reservations # reservations_arr = [] # reservation = Hotel::Reservation.new - # input[:start_date] + # input[:checkout_date] # input[:end_date] # reservations_arr << reservation # return reservations_arr diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb index 077349a32..09e903931 100644 --- a/specs/hotel_admin_spec.rb +++ b/specs/hotel_admin_spec.rb @@ -22,7 +22,7 @@ it "calculates the cost of a given reservation" do hotel_admin = Hotel::HotelAdmin.new room = Hotel::Room.new("unit_name") - reservation = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25", room_id: 1}) + reservation = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) hotel_admin.calc_reservations(room, reservation).must_equal 1000 end end @@ -34,20 +34,22 @@ it "returns a list of reservations for a specific date" do hotel_admin = Hotel::HotelAdmin.new - reservation_a = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25", room_id: 1}) - reservation_b = Hotel::Reservation.new({start_date: "2015-07-21", end_date: "2015-07-25", room_id: 2}) + reservation_a = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) + reservation_b = Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2}) hotel_admin.add_reservation(reservation_a) hotel_admin.add_reservation(reservation_b) - hotel_admin.access_reservations("2015-07-20").must_equal [reservation_a] + hotel_admin.access_reservations("2015-07-21").must_equal [reservation_a] hotel_admin.access_reservations("2015-07-22").must_equal [reservation_a, reservation_b] + hotel_admin.access_reservations("2015-07-19").must_equal [] + hotel_admin.access_reservations("2015-07-25").must_equal [] end - - - it "returns a list of rooms" do - - - end + # it "returns a list of rooms" do + # hotel_admin = Hotel::HotelAdmin.new + # hotel_admin.load_rooms + # puts hotel_admin.rooms.length must_equal 20 + # #hotel_admin.rooms.length must_equal 20 + # end it "can reserve a room for a given date range" do From 66170d4772fdcca7a2e4f67faebfd5ee7dc2f895 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Thu, 8 Mar 2018 09:52:25 -0800 Subject: [PATCH 13/43] changed start_date and end_date to checkin_date and checkout_date --- lib/reservation.rb | 24 ++++++++++++------------ specs/reservation_spec.rb | 12 ++++++------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 25a9499f8..49b4ca200 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -2,43 +2,43 @@ module Hotel class Reservation - attr_reader :start_date, :end_date + attr_reader :checkin_date, :checkout_date def initialize(input) - if input[:start_date] == nil || input[:end_date] == nil + if input[:checkin_date] == nil || input[:checkout_date] == nil raise ArgumentError.new("Date must be a date.") end - input[:start_date] = Time.parse(input[:start_date]) - input[:end_date] = Time.parse(input[:end_date]) + input[:checkin_date] = Time.parse(input[:checkin_date]) + input[:checkout_date] = Time.parse(input[:checkout_date]) - if input[:start_date] >= input[:end_date] + if input[:checkin_date] >= input[:checkout_date] raise ArgumentError.new("End date must be after start date.") end #add room_id ArgumentError if necessary - @start_date = input[:start_date] - @end_date = input[:end_date] + @checkin_date = input[:checkin_date] + @checkout_date = input[:checkout_date] @room_id = input[:room_id] end def length - ((@end_date - @start_date) / 86400).to_i + ((@checkout_date - @checkin_date) / 86400).to_i end # def puts_self # puts Hotel::Reservation.new # end - def start_date - @start_date + def checkin_date + @checkin_date end - def end_date - @end_date + def checkout_date + @checkout_date end #.strftime("%m/%d/%Y") diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 0fc6a83d7..b3929c31c 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -3,27 +3,27 @@ describe "Reservation class" do describe "Initializer" do it "is an instance of Reservation" do - reservation = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25"}) + reservation = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25"}) reservation.must_be_kind_of Hotel::Reservation end it "throws an argument error for a bad start date" do - proc{ Hotel::Reservation.new({start_date: nil, end_date: "2015-07-20" }) }.must_raise ArgumentError + proc{ Hotel::Reservation.new({checkin_date: nil, checkout_date: "2015-07-20" }) }.must_raise ArgumentError end it "throws an argument error for a bad end date" do - proc{ Hotel::Reservation.new({start_date: "2015-07-20", end_date: nil }) }.must_raise ArgumentError + proc{ Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: nil }) }.must_raise ArgumentError end it "throws an argument error when end date isn't after start date" do - proc{ Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-20" }) }.must_raise ArgumentError - proc{ Hotel::Reservation.new({start_date: "2015-07-21", end_date: "2015-07-20" }) }.must_raise ArgumentError + proc{ Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-20" }) }.must_raise ArgumentError + proc{ Hotel::Reservation.new({checkin_date: "2015-07-21", checkout_date: "2015-07-20" }) }.must_raise ArgumentError end end describe "length method" do it "calculates the number of nights for the hotel stay" do - @reservation = Hotel::Reservation.new({start_date: "2015-07-20", end_date: "2015-07-25"}) + @reservation = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25"}) @reservation.length.must_equal 5 @reservation.length.must_be_kind_of Integer end From de77f643d9eb1f9b80cf2500a76db28a724c2e17 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Thu, 8 Mar 2018 12:57:02 -0800 Subject: [PATCH 14/43] adjusted variable names in lib/hotel_admin.rb for added clarity --- lib/hotel_admin.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/hotel_admin.rb b/lib/hotel_admin.rb index 574564c7e..395e65851 100644 --- a/lib/hotel_admin.rb +++ b/lib/hotel_admin.rb @@ -12,25 +12,21 @@ def initialize end def load_rooms - room_arr = [] + rooms_arr = [] [*1..20].each do |n| room = Room.new(n) - # @unit = unit - room_arr << room + rooms_arr << room end - @rooms = room_arr - return @rooms #room_arr + @rooms = rooms_arr + return @rooms end def add_reservation(reservation) - # new_reservation = (reservation) - # reservations_arr << new_reservation @reservations << reservation - # @reservation = new_reservation end def calc_reservations(room, reservation) - room.price * reservation.length + room.price * reservation.calc_duration end def access_reservations(day) From daddef4ead27666d238ac3c1f26d3685f2b061ed Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Thu, 8 Mar 2018 12:58:01 -0800 Subject: [PATCH 15/43] updated tests for HotelAdmin's method of returning rooms --- specs/hotel_admin_spec.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb index 09e903931..32ae922a9 100644 --- a/specs/hotel_admin_spec.rb +++ b/specs/hotel_admin_spec.rb @@ -28,9 +28,6 @@ end describe "dates reservations method" do - # before do - # hotel_admin = Hotel::HotelAdmin.new - # end it "returns a list of reservations for a specific date" do hotel_admin = Hotel::HotelAdmin.new @@ -44,12 +41,12 @@ hotel_admin.access_reservations("2015-07-25").must_equal [] end - # it "returns a list of rooms" do - # hotel_admin = Hotel::HotelAdmin.new - # hotel_admin.load_rooms - # puts hotel_admin.rooms.length must_equal 20 - # #hotel_admin.rooms.length must_equal 20 - # end + it "returns a list of rooms" do + hotel_admin = Hotel::HotelAdmin.new + hotel_admin.load_rooms + hotel_admin.rooms.must_be_kind_of Array + hotel_admin.rooms.wont_be_nil + end it "can reserve a room for a given date range" do From 3680efeb1ce4a27205b9c5733ac29c0f0bcb8f9d Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Thu, 8 Mar 2018 12:58:54 -0800 Subject: [PATCH 16/43] adjusted variable names in lib/room.rb for added clarity --- lib/room.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index 7f5af7f43..578c4a65e 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,11 +1,11 @@ module Hotel class Room - attr_reader :room, :cost + attr_reader :room_num, :cost COST = 200 def initialize(room_num) - @room = room_num + @room_num = room_num end def price From 883b1a11d1ae3f15338f38be35e63e58e13555e6 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Thu, 8 Mar 2018 12:59:30 -0800 Subject: [PATCH 17/43] adjusted method names in lib/reservation.rb for added clarity --- lib/reservation.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 49b4ca200..0536052f4 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -2,7 +2,7 @@ module Hotel class Reservation - attr_reader :checkin_date, :checkout_date + attr_reader :checkin_date, :checkout_date, :room_id def initialize(input) @@ -25,7 +25,7 @@ def initialize(input) end - def length + def calc_duration ((@checkout_date - @checkin_date) / 86400).to_i end From ca4ff0d911530f72c1b9f948f8df54b7eb492ac5 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Thu, 8 Mar 2018 13:00:09 -0800 Subject: [PATCH 18/43] updated tests to account for adjusted method names in lib/reservation.rb for added clarity --- specs/reservation_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index b3929c31c..9eea02c5d 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -21,11 +21,11 @@ end end - describe "length method" do + describe "calc_duration method" do it "calculates the number of nights for the hotel stay" do @reservation = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25"}) - @reservation.length.must_equal 5 - @reservation.length.must_be_kind_of Integer + @reservation.calc_duration.must_equal 5 + @reservation.calc_duration.must_be_kind_of Integer end end From 44b474c0848c8b201cf95a04137063788750c2ff Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Thu, 8 Mar 2018 13:03:11 -0800 Subject: [PATCH 19/43] rearranged order of hotel_admin tests --- specs/hotel_admin_spec.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb index 32ae922a9..8a86a7c9b 100644 --- a/specs/hotel_admin_spec.rb +++ b/specs/hotel_admin_spec.rb @@ -18,15 +18,6 @@ end - describe "calculates reservation cost" do - it "calculates the cost of a given reservation" do - hotel_admin = Hotel::HotelAdmin.new - room = Hotel::Room.new("unit_name") - reservation = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) - hotel_admin.calc_reservations(room, reservation).must_equal 1000 - end - end - describe "dates reservations method" do it "returns a list of reservations for a specific date" do @@ -54,7 +45,13 @@ end - - + describe "calculates reservation cost" do + it "calculates the cost of a given reservation" do + hotel_admin = Hotel::HotelAdmin.new + room = Hotel::Room.new("unit_name") + reservation = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) + hotel_admin.calc_reservations(room, reservation).must_equal 1000 + end + end end From ee581ee6f2458a40601a1e38580d34538edf8b41 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Thu, 8 Mar 2018 13:17:16 -0800 Subject: [PATCH 20/43] rearrange order of methods --- lib/reservation.rb | 19 +++++++++++-------- specs/hotel_admin_spec.rb | 12 +++++++----- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 0536052f4..b4e259cd0 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -33,14 +33,17 @@ def calc_duration # puts Hotel::Reservation.new # end - def checkin_date - @checkin_date - end - - def checkout_date - @checkout_date - end - + # def checkin_date + # @checkin_date + # end + # + # def checkout_date + # @checkout_date + # end + # + # def room_id + # @room_id + # end #.strftime("%m/%d/%Y") # def self.all diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb index 8a86a7c9b..91defd1f0 100644 --- a/specs/hotel_admin_spec.rb +++ b/specs/hotel_admin_spec.rb @@ -20,6 +20,10 @@ describe "dates reservations method" do + it "can reserve a room for a given date range" do + + end + it "returns a list of reservations for a specific date" do hotel_admin = Hotel::HotelAdmin.new reservation_a = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) @@ -32,17 +36,15 @@ hotel_admin.access_reservations("2015-07-25").must_equal [] end + end + + describe "load rooms method" do it "returns a list of rooms" do hotel_admin = Hotel::HotelAdmin.new hotel_admin.load_rooms hotel_admin.rooms.must_be_kind_of Array hotel_admin.rooms.wont_be_nil end - - it "can reserve a room for a given date range" do - - end - end describe "calculates reservation cost" do From 3aee111828023c26f799a4315c1fa572e072dd51 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Thu, 8 Mar 2018 21:58:39 -0800 Subject: [PATCH 21/43] removed room class and specs, added room to HotelAdmin class. updated classes and tests as a result --- lib/hotel_admin.rb | 40 +++++++----------------------- lib/reservation.rb | 31 ++++------------------- lib/room.rb | 32 ++++++++++++------------ specs/hotel_admin_spec.rb | 19 +++++--------- specs/reservation_spec.rb | 3 ++- specs/room_spec.rb | 52 +++++++++++++++++++-------------------- 6 files changed, 64 insertions(+), 113 deletions(-) diff --git a/lib/hotel_admin.rb b/lib/hotel_admin.rb index 395e65851..9a9d13326 100644 --- a/lib/hotel_admin.rb +++ b/lib/hotel_admin.rb @@ -4,56 +4,34 @@ module Hotel class HotelAdmin - attr_reader :rooms, :reservations, :unit, :reservation + attr_reader :rooms, :reservations, :reservation def initialize - @rooms = [] + @rooms = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] @reservations = [] end - def load_rooms - rooms_arr = [] - [*1..20].each do |n| - room = Room.new(n) - rooms_arr << room - end - @rooms = rooms_arr - return @rooms - end - def add_reservation(reservation) @reservations << reservation + @reservation = reservation + return @reservation end - def calc_reservations(room, reservation) - room.price * reservation.calc_duration + def calc_reservations(reservation) + reservation.price_night * reservation.calc_duration end def access_reservations(day) days_reservations = [] @reservations.each do |reservation| - checkin_date_loc = reservation.checkin_date.strftime("%Y-%m-%d") - checkout_date_loc = reservation.checkout_date.strftime("%Y-%m-%d") - if (checkin_date_loc...checkout_date_loc).include?(day) - + checkin_date_local = reservation.checkin_date.strftime("%Y-%m-%d") + checkout_date_local = reservation.checkout_date.strftime("%Y-%m-%d") + if (checkin_date_local...checkout_date_local).include?(day) days_reservations << reservation end end return days_reservations end - # def load_reservations - # reservations_arr = [] - # reservation = Hotel::Reservation.new - # input[:checkout_date] - # input[:end_date] - # reservations_arr << reservation - # return reservations_arr - # end - - # def load_reservations - # - # end - end end diff --git a/lib/reservation.rb b/lib/reservation.rb index b4e259cd0..88c1538de 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -17,41 +17,20 @@ def initialize(input) raise ArgumentError.new("End date must be after start date.") end - #add room_id ArgumentError if necessary - @checkin_date = input[:checkin_date] @checkout_date = input[:checkout_date] @room_id = input[:room_id] + @price_night = 200 + + end + def price_night + @price_night end def calc_duration ((@checkout_date - @checkin_date) / 86400).to_i end - # def puts_self - # puts Hotel::Reservation.new - # end - - # def checkin_date - # @checkin_date - # end - # - # def checkout_date - # @checkout_date - # end - # - # def room_id - # @room_id - # end - #.strftime("%m/%d/%Y") - - # def self.all - # reservations_arr = [] - # @reservation - # reservations_arr << reservation - # return reservations_arr - # end - end end diff --git a/lib/room.rb b/lib/room.rb index 578c4a65e..30db78833 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,16 +1,16 @@ - -module Hotel - class Room - attr_reader :room_num, :cost - COST = 200 - - def initialize(room_num) - @room_num = room_num - end - - def price - @cost = COST - end - - end -end +# +# module Hotel +# class Room +# attr_reader :room_num, :cost +# COST = 200 +# +# def initialize(room_num) +# @room_num = room_num +# end +# +# # def price +# # @cost = COST +# # end +# +# end +# end diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb index 91defd1f0..915fd9c7c 100644 --- a/specs/hotel_admin_spec.rb +++ b/specs/hotel_admin_spec.rb @@ -21,7 +21,10 @@ describe "dates reservations method" do it "can reserve a room for a given date range" do - + hotel_admin = Hotel::HotelAdmin.new + reservation_a = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) + new_res = hotel_admin.add_reservation(reservation_a) + hotel_admin.reservations.must_include new_res end it "returns a list of reservations for a specific date" do @@ -35,24 +38,14 @@ hotel_admin.access_reservations("2015-07-19").must_equal [] hotel_admin.access_reservations("2015-07-25").must_equal [] end - - end - - describe "load rooms method" do - it "returns a list of rooms" do - hotel_admin = Hotel::HotelAdmin.new - hotel_admin.load_rooms - hotel_admin.rooms.must_be_kind_of Array - hotel_admin.rooms.wont_be_nil - end end describe "calculates reservation cost" do it "calculates the cost of a given reservation" do hotel_admin = Hotel::HotelAdmin.new - room = Hotel::Room.new("unit_name") reservation = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) - hotel_admin.calc_reservations(room, reservation).must_equal 1000 + hotel_admin.calc_reservations(reservation).must_equal 1000 + hotel_admin.calc_reservations(reservation).must_be_instance_of Integer end end diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 9eea02c5d..76533a334 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -3,8 +3,9 @@ describe "Reservation class" do describe "Initializer" do it "is an instance of Reservation" do - reservation = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25"}) + reservation = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) reservation.must_be_kind_of Hotel::Reservation + reservation.class.must_equal Hotel::Reservation end it "throws an argument error for a bad start date" do diff --git a/specs/room_spec.rb b/specs/room_spec.rb index c3f400a93..ac4d93d8c 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -1,26 +1,26 @@ -require_relative 'spec_helper' - -describe "Room class" do - - describe "Initializer" do - it "Can be created" do - room = Hotel::Room.new("unit_name") - room.must_be_instance_of Hotel::Room - end - - it "Is an instance of Room" do - room = Hotel::Room.new("unit_name") - room.class.must_equal Hotel::Room - end - - end - - describe "price method" do - it "returns price" do - room = Hotel::Room.new("unit_name") - room.price.must_equal 200 - room.price.must_be_kind_of Integer - end - end - -end +# require_relative 'spec_helper' +# +# describe "Room class" do +# +# describe "Initializer" do +# it "Can be created" do +# room = Hotel::Room.new("unit_name") +# room.must_be_instance_of Hotel::Room +# end +# +# it "Is an instance of Room" do +# room = Hotel::Room.new("unit_name") +# room.class.must_equal Hotel::Room +# end +# +# end +# +# describe "price method" do +# it "returns price" do +# room = Hotel::Room.new("unit_name") +# room.price.must_equal 200 +# room.price.must_be_kind_of Integer +# end +# end +# +# end From 32815d1eee25d2b07122e7844af399b0c071af3c Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Sun, 11 Mar 2018 19:09:50 -0700 Subject: [PATCH 22/43] updated reservation class to grey out lines that parsed the date into seconds --- lib/reservation.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 88c1538de..ae53cc762 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -10,8 +10,8 @@ def initialize(input) raise ArgumentError.new("Date must be a date.") end - input[:checkin_date] = Time.parse(input[:checkin_date]) - input[:checkout_date] = Time.parse(input[:checkout_date]) + # input[:checkin_date] = Time.parse(input[:checkin_date]) + # input[:checkout_date] = Time.parse(input[:checkout_date]) if input[:checkin_date] >= input[:checkout_date] raise ArgumentError.new("End date must be after start date.") @@ -29,7 +29,8 @@ def price_night end def calc_duration - ((@checkout_date - @checkin_date) / 86400).to_i + # ((@checkout_date - @checkin_date) / 86400).to_i + ((checkin_date...checkout_date).map{ |date| date}).count end end From c633a11d244154c719cb40e093235e4c9420798d Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Sun, 11 Mar 2018 19:13:14 -0700 Subject: [PATCH 23/43] add test to HotelAdmin class to check that returns a list of all the rooms and views a list of rooms that aren't reserved for a given range --- specs/hotel_admin_spec.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb index 915fd9c7c..ea72b171c 100644 --- a/specs/hotel_admin_spec.rb +++ b/specs/hotel_admin_spec.rb @@ -16,10 +16,13 @@ hotel_admin.reservations.must_be_kind_of Array end + it "lists of all of the rooms in the hotel" do + hotel_admin = Hotel::HotelAdmin.new + hotel_admin.rooms.must_equal [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] + end end describe "dates reservations method" do - it "can reserve a room for a given date range" do hotel_admin = Hotel::HotelAdmin.new reservation_a = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) @@ -49,4 +52,27 @@ end end + describe "can view a list of rooms that are not reserved for a given date range" do + it "can test 1" do + hotel_admin = Hotel::HotelAdmin.new + reservation_a = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) + reservation_b = Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2}) + hotel_admin.add_reservation(reservation_a) + hotel_admin.add_reservation(reservation_b) + hotel_admin.view_available_rooms("2015-07-20", "2015-07-23").must_equal [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + end + end + + # describe "can reserve an available room for a given date range" do + # it "" do + # hotel_admin = Hotel::HotelAdmin.new + # reservation_a = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) + # reservation_b = Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2}) + # hotel_admin.add_reservation(reservation_a) + # hotel_admin.add_reservation(reservation_b) + # hotel_admin.reserve_available_room("2015-07-20", "2015-07-23").room_id.must_equal 3 + # + # end + # end + end From de23dda9df2cd97aa00ef4558da322c55156dd6a Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Sun, 11 Mar 2018 19:15:05 -0700 Subject: [PATCH 24/43] In HotelAdmin class, added method to view available rooms, and changed access_reservation method to remove strftime(%Y-%m-%d) functionality --- lib/hotel_admin.rb | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/hotel_admin.rb b/lib/hotel_admin.rb index 9a9d13326..3b5dc4a41 100644 --- a/lib/hotel_admin.rb +++ b/lib/hotel_admin.rb @@ -12,6 +12,7 @@ def initialize end def add_reservation(reservation) + #note: this is tightly coupled, I think. @reservations << reservation @reservation = reservation return @reservation @@ -24,14 +25,31 @@ def calc_reservations(reservation) def access_reservations(day) days_reservations = [] @reservations.each do |reservation| - checkin_date_local = reservation.checkin_date.strftime("%Y-%m-%d") - checkout_date_local = reservation.checkout_date.strftime("%Y-%m-%d") - if (checkin_date_local...checkout_date_local).include?(day) + # checkin_date_local = reservation.checkin_date.strftime("%Y-%m-%d") + # checkout_date_local = reservation.checkout_date.strftime("%Y-%m-%d") + if (reservation.checkin_date...reservation.checkout_date).include?(day) days_reservations << reservation end end return days_reservations end + def view_available_rooms(checkin_request, checkout_request) + arr_available_rooms = @rooms.map{ |room| room } + date_range_requested = (checkin_request...checkout_request).map{ |date| date} + @reservations.each do |res| + date_range_requested.each do |day_requested| + if (res.checkin_date...res.checkout_date).include?(day_requested) + arr_available_rooms.delete(res.room_id) + end + end + end + return arr_available_rooms + end + + # def reserve_available_room(checkin_request, checkout_request) + # + # end + end end From 9fef03e9ea4c1e3b9edcf7a4386efa7ea3741020 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Sun, 11 Mar 2018 20:00:23 -0700 Subject: [PATCH 25/43] removed unnecessary comments --- lib/reservation.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index ae53cc762..e520125e8 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -10,9 +10,6 @@ def initialize(input) raise ArgumentError.new("Date must be a date.") end - # input[:checkin_date] = Time.parse(input[:checkin_date]) - # input[:checkout_date] = Time.parse(input[:checkout_date]) - if input[:checkin_date] >= input[:checkout_date] raise ArgumentError.new("End date must be after start date.") end @@ -29,7 +26,6 @@ def price_night end def calc_duration - # ((@checkout_date - @checkin_date) / 86400).to_i ((checkin_date...checkout_date).map{ |date| date}).count end From 779da5caa25accbd5b973a6d73189ce188abd541 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Sun, 11 Mar 2018 20:02:36 -0700 Subject: [PATCH 26/43] removed unnecessary comments and added reserve_available_room method lib/hotel_admin.rb --- lib/hotel_admin.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/hotel_admin.rb b/lib/hotel_admin.rb index 3b5dc4a41..58c06c107 100644 --- a/lib/hotel_admin.rb +++ b/lib/hotel_admin.rb @@ -25,8 +25,6 @@ def calc_reservations(reservation) def access_reservations(day) days_reservations = [] @reservations.each do |reservation| - # checkin_date_local = reservation.checkin_date.strftime("%Y-%m-%d") - # checkout_date_local = reservation.checkout_date.strftime("%Y-%m-%d") if (reservation.checkin_date...reservation.checkout_date).include?(day) days_reservations << reservation end @@ -47,9 +45,10 @@ def view_available_rooms(checkin_request, checkout_request) return arr_available_rooms end - # def reserve_available_room(checkin_request, checkout_request) - # - # end + def reserve_available_room(checkin_request, checkout_request) + avail_room = view_available_rooms(checkin_request, checkout_request)[0] + add_reservation(Hotel::Reservation.new({checkin_date: checkin_request, checkout_date: checkout_request, room_id: avail_room})) + end end end From a217f7ea39800a6a60634a7f2cddf4a58e86fd33 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Sun, 11 Mar 2018 20:03:52 -0700 Subject: [PATCH 27/43] removed unnecessary comments and added tests for reserve_available_room method in hotel class.rb --- specs/hotel_admin_spec.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb index ea72b171c..a82f021c3 100644 --- a/specs/hotel_admin_spec.rb +++ b/specs/hotel_admin_spec.rb @@ -63,16 +63,20 @@ end end - # describe "can reserve an available room for a given date range" do - # it "" do - # hotel_admin = Hotel::HotelAdmin.new - # reservation_a = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) - # reservation_b = Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2}) - # hotel_admin.add_reservation(reservation_a) - # hotel_admin.add_reservation(reservation_b) - # hotel_admin.reserve_available_room("2015-07-20", "2015-07-23").room_id.must_equal 3 - # - # end - # end + describe "can reserve an available room for a given date range" do + it "" do + hotel_admin = Hotel::HotelAdmin.new + reservation_a = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) + reservation_b = Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2}) + hotel_admin.add_reservation(reservation_a) + hotel_admin.add_reservation(reservation_b) + new_res = hotel_admin.reserve_available_room("2015-07-20", "2015-07-23") + new_res.must_be_kind_of Hotel::Reservation + new_res.checkin_date.must_equal "2015-07-20" + new_res.checkout_date.must_equal "2015-07-23" + new_res.room_id.must_equal 3 + + end + end end From 21fbb57412061fe7dba1df2f850373720452ceec Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Sun, 11 Mar 2018 21:45:32 -0700 Subject: [PATCH 28/43] trimmed down the tests for the HotelAdmin class's methods --- specs/hotel_admin_spec.rb | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb index a82f021c3..a4ac39c61 100644 --- a/specs/hotel_admin_spec.rb +++ b/specs/hotel_admin_spec.rb @@ -25,17 +25,14 @@ describe "dates reservations method" do it "can reserve a room for a given date range" do hotel_admin = Hotel::HotelAdmin.new - reservation_a = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) - new_res = hotel_admin.add_reservation(reservation_a) + new_res = hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1})) hotel_admin.reservations.must_include new_res end it "returns a list of reservations for a specific date" do hotel_admin = Hotel::HotelAdmin.new - reservation_a = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) - reservation_b = Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2}) - hotel_admin.add_reservation(reservation_a) - hotel_admin.add_reservation(reservation_b) + reservation_a = hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1})) + reservation_b = hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2})) hotel_admin.access_reservations("2015-07-21").must_equal [reservation_a] hotel_admin.access_reservations("2015-07-22").must_equal [reservation_a, reservation_b] hotel_admin.access_reservations("2015-07-19").must_equal [] @@ -46,7 +43,7 @@ describe "calculates reservation cost" do it "calculates the cost of a given reservation" do hotel_admin = Hotel::HotelAdmin.new - reservation = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) + reservation = hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1})) hotel_admin.calc_reservations(reservation).must_equal 1000 hotel_admin.calc_reservations(reservation).must_be_instance_of Integer end @@ -55,10 +52,8 @@ describe "can view a list of rooms that are not reserved for a given date range" do it "can test 1" do hotel_admin = Hotel::HotelAdmin.new - reservation_a = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) - reservation_b = Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2}) - hotel_admin.add_reservation(reservation_a) - hotel_admin.add_reservation(reservation_b) + hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1})) + hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2})) hotel_admin.view_available_rooms("2015-07-20", "2015-07-23").must_equal [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] end end @@ -66,16 +61,13 @@ describe "can reserve an available room for a given date range" do it "" do hotel_admin = Hotel::HotelAdmin.new - reservation_a = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) - reservation_b = Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2}) - hotel_admin.add_reservation(reservation_a) - hotel_admin.add_reservation(reservation_b) + hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1})) + hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2})) new_res = hotel_admin.reserve_available_room("2015-07-20", "2015-07-23") new_res.must_be_kind_of Hotel::Reservation new_res.checkin_date.must_equal "2015-07-20" new_res.checkout_date.must_equal "2015-07-23" new_res.room_id.must_equal 3 - end end From 5982f913ee6ca9870963fadd0ae50ede82718dbe Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Sun, 11 Mar 2018 21:48:48 -0700 Subject: [PATCH 29/43] add block class lib and spec files --- lib/block.rb | 9 +++++++++ specs/block_spec.rb | 1 + 2 files changed, 10 insertions(+) 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..d5284c433 --- /dev/null +++ b/lib/block.rb @@ -0,0 +1,9 @@ +require 'time' +require_relative 'reservation' +require_relative 'hotel_admin' + +module Hotel + class HotelAdmin + + end +end diff --git a/specs/block_spec.rb b/specs/block_spec.rb new file mode 100644 index 000000000..ae9c220ea --- /dev/null +++ b/specs/block_spec.rb @@ -0,0 +1 @@ +require_relative 'spec_helper' From 474e97da9de47f31a75c393b97d17463ba4cade6 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Sun, 11 Mar 2018 21:55:37 -0700 Subject: [PATCH 30/43] added lib/block and removed lib/room as required relatives --- specs/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index e2c427827..c3733cd4a 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -9,4 +9,4 @@ require_relative '../lib/hotel_admin' require_relative '../lib/reservation' -require_relative '../lib/room' +require_relative '../lib/block' From 428a5a968e115fcfc08b88730b5cf7069210b885 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Sun, 11 Mar 2018 21:56:33 -0700 Subject: [PATCH 31/43] removed lib/room as required relative --- lib/hotel_admin.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/hotel_admin.rb b/lib/hotel_admin.rb index 58c06c107..d6b27463f 100644 --- a/lib/hotel_admin.rb +++ b/lib/hotel_admin.rb @@ -1,6 +1,5 @@ require 'time' require_relative 'reservation' -require_relative 'room' module Hotel class HotelAdmin From edb381065c1f675933a473828cc668fcc0bd7542 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Mon, 12 Mar 2018 00:18:12 -0700 Subject: [PATCH 32/43] holding off on making block its own class for now --- lib/block.rb | 47 +++++++++++++++++++++++------ lib/hotel_admin.rb | 2 +- specs/block_spec.rb | 72 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 110 insertions(+), 11 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index d5284c433..74d6fd8fc 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -1,9 +1,38 @@ -require 'time' -require_relative 'reservation' -require_relative 'hotel_admin' - -module Hotel - class HotelAdmin - - end -end +# require 'time' +# require_relative 'reservation' +# require_relative 'hotel_admin' +# +# module Hotel +# class Block +# attr_reader :block_start_date, :block_end_date, :room_amt +# +# def initialize(input) +# +# if input[:block_start_date] == nil || input[:block_end_date] == nil +# raise ArgumentError.new("Date must be a date.") +# end +# +# if input[:block_start_date] >= input[:block_end_date] +# raise ArgumentError.new("End date must be after start date.") +# end +# +# if input[:room_amt] > 5 || input[:room_amt] < 1 +# raise ArgumentError.new("Rooms must be between 1 and 5.") +# end +# +# # if input[:room_num] > Hotel::HotelAdmin.view_available_rooms(input[:block_start_date], input[:block_end_date]) +# # raise ArgumentError.new("There are not enough rooms available during that time.") +# # end +# +# if input[:room_amt] > 5 || input[:room_amt] < 1 +# raise ArgumentError.new("Rooms must be between 1 and 5.") +# end +# +# @block_start_date = input[:block_start_date] +# @block_end_date = input[:block_end_date] +# @room_num = input[:room_amt] +# end +# +# +# end +# end diff --git a/lib/hotel_admin.rb b/lib/hotel_admin.rb index d6b27463f..3e31179a2 100644 --- a/lib/hotel_admin.rb +++ b/lib/hotel_admin.rb @@ -13,7 +13,7 @@ def initialize def add_reservation(reservation) #note: this is tightly coupled, I think. @reservations << reservation - @reservation = reservation + # @reservation = reservation return @reservation end diff --git a/specs/block_spec.rb b/specs/block_spec.rb index ae9c220ea..9650ce095 100644 --- a/specs/block_spec.rb +++ b/specs/block_spec.rb @@ -1 +1,71 @@ -require_relative 'spec_helper' +# require_relative 'spec_helper' +# +# +# describe "Block class" do +# +# describe "Initializer" do +# before do +# @block = Hotel::Block.new({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_num: 5}) +# end +# +# it "is an instance of Hotel::Block" do +# @block.must_be_kind_of Hotel::Block +# end +# +# it "returns an error if block attempt has more than 5 rooms" do +# proc{ Hotel::Block.new({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_num: 6})}.must_raise ArgumentError +# end +# +# it "returns an error if block attempt has less than 1 room" do +# proc{ Hotel::Block.new({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_num: 0})}.must_raise ArgumentError +# end +# +# it "throws an argument error for a bad end date" do +# proc{ Hotel::Block.new({block_start_date: "2015-07-20", block_end_date: nil }) }.must_raise ArgumentError +# end +# +# it "throws an argument error for a bad start date" do +# proc{ Hotel::Block.new({block_start_date: nil, block_end_date: "2015-07-20", room_num: 3 }) }.must_raise ArgumentError +# end +# +# +# it "throws an argument error when end date isn't after start date" do +# proc{ Hotel::Block.new({block_start_date: "2015-07-20", block_end_date: "2015-07-20", room_num: 3 }) }.must_raise ArgumentError +# proc{ Hotel::Block.new({block_start_date: "2015-07-21", block_end_date: "2015-07-20", room_num: 3 }) }.must_raise ArgumentError +# end +# +# it "can create a block of rooms" do +# +# end +# +# it "only includes rooms that are available for the given date range" do +# +# end +# +# it "excludes rooms in the block for reservations by general public" do +# end +# +# end +# +# # describe "create_block method" do +# # +# # it "" do +# # end +# # +# # end +# +# describe "check_block_availability method" do +# +# it "can check whether a given block has any rooms available" do +# end +# +# end +# +# describe "reserve_room_in_block" do +# +# it "can reserve a room from within a block of rooms" do +# end +# +# end +# +# end From a0042c2cea6d227694a2f67b02d872d94658b0e0 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Mon, 12 Mar 2018 00:18:25 -0700 Subject: [PATCH 33/43] holding off on making block its own class for now --- specs/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index c3733cd4a..bfe0d866e 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -9,4 +9,4 @@ require_relative '../lib/hotel_admin' require_relative '../lib/reservation' -require_relative '../lib/block' +#require_relative '../lib/block' From ba3c378017b720aeea927c40c91f848ce8b44608 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Mon, 12 Mar 2018 00:19:25 -0700 Subject: [PATCH 34/43] small format change --- specs/reservation_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 76533a334..36f8ca2f6 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -2,6 +2,7 @@ describe "Reservation class" do describe "Initializer" do + it "is an instance of Reservation" do reservation = Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1}) reservation.must_be_kind_of Hotel::Reservation From 9c6e3e475907596ff3cd8642bcfb736a020eb016 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Mon, 12 Mar 2018 00:20:14 -0700 Subject: [PATCH 35/43] updated HotelAdmin class and its tests to include block functionality --- lib/hotel_admin.rb | 37 +++++++++++- specs/hotel_admin_spec.rb | 120 ++++++++++++++++++++++++++++++++------ 2 files changed, 136 insertions(+), 21 deletions(-) diff --git a/lib/hotel_admin.rb b/lib/hotel_admin.rb index 3e31179a2..0f9282a80 100644 --- a/lib/hotel_admin.rb +++ b/lib/hotel_admin.rb @@ -3,17 +3,18 @@ module Hotel class HotelAdmin - attr_reader :rooms, :reservations, :reservation + attr_reader :rooms, :reservations, :reservation, :block_start_date, :block_end_date, :room_amt, :blocks, :block def initialize @rooms = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] @reservations = [] + @blocks = [] end def add_reservation(reservation) #note: this is tightly coupled, I think. @reservations << reservation - # @reservation = reservation + @reservation = reservation return @reservation end @@ -49,5 +50,37 @@ def reserve_available_room(checkin_request, checkout_request) add_reservation(Hotel::Reservation.new({checkin_date: checkin_request, checkout_date: checkout_request, room_id: avail_room})) end + + def create_block(input) + + if input[:block_start_date] == nil || input[:block_end_date] == nil + raise ArgumentError.new("Date must be a date.") + end + + if input[:block_start_date] >= input[:block_end_date] + raise ArgumentError.new("End date must be after start date.") + end + + if input[:room_amt] > 5 || input[:room_amt] < 1 + raise ArgumentError.new("Rooms must be between 1 and 5.") + end + + if input[:room_amt] > 5 || input[:room_amt] < 1 + raise ArgumentError.new("Rooms must be between 1 and 5.") + end + + if input[:room_amt] > view_available_rooms(input[:block_start_date], input[:block_end_date]).count + raise ArgumentError.new("There are not enough rooms available during that time.") + end + + @block_start_date = input[:block_start_date] + @block_end_date = input[:block_end_date] + @room_num = input[:room_amt] + @blocks << input + @block = input + return @block + end + + end end diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb index a4ac39c61..9e4bd818d 100644 --- a/specs/hotel_admin_spec.rb +++ b/specs/hotel_admin_spec.rb @@ -2,41 +2,46 @@ describe "HotelAdmin class" do describe "Initializer" do - it "is an instance of TripDispatcher" do - hotel_admin = Hotel::HotelAdmin.new - hotel_admin.must_be_kind_of Hotel::HotelAdmin + before do + @hotel_admin = Hotel::HotelAdmin.new + end + + it "is an instance of HotelAdmin" do + @hotel_admin.must_be_kind_of Hotel::HotelAdmin end it "establishes the base data structures when instantiated" do - hotel_admin = Hotel::HotelAdmin.new [:rooms, :reservations].each do |i| - hotel_admin.must_respond_to i + @hotel_admin.must_respond_to i end - hotel_admin.rooms.must_be_kind_of Array - hotel_admin.reservations.must_be_kind_of Array + @hotel_admin.rooms.must_be_kind_of Array + @hotel_admin.reservations.must_be_kind_of Array end it "lists of all of the rooms in the hotel" do - hotel_admin = Hotel::HotelAdmin.new - hotel_admin.rooms.must_equal [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] + @hotel_admin.rooms.must_equal [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] + @hotel_admin.rooms.first.must_equal 1 + @hotel_admin.rooms.last.must_equal 20 end end describe "dates reservations method" do + before do + @hotel_admin = Hotel::HotelAdmin.new + end + it "can reserve a room for a given date range" do - hotel_admin = Hotel::HotelAdmin.new - new_res = hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1})) - hotel_admin.reservations.must_include new_res + new_res = @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1})) + @hotel_admin.reservations.must_include new_res end it "returns a list of reservations for a specific date" do - hotel_admin = Hotel::HotelAdmin.new - reservation_a = hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1})) - reservation_b = hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2})) - hotel_admin.access_reservations("2015-07-21").must_equal [reservation_a] - hotel_admin.access_reservations("2015-07-22").must_equal [reservation_a, reservation_b] - hotel_admin.access_reservations("2015-07-19").must_equal [] - hotel_admin.access_reservations("2015-07-25").must_equal [] + reservation_a = @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1})) + reservation_b = @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-22", checkout_date: "2015-07-24", room_id: 2})) + @hotel_admin.access_reservations("2015-07-21").must_equal [reservation_a] + @hotel_admin.access_reservations("2015-07-22").must_equal [reservation_a, reservation_b] + @hotel_admin.access_reservations("2015-07-19").must_equal [] + @hotel_admin.access_reservations("2015-07-25").must_equal [] end end @@ -71,4 +76,81 @@ end end + describe "creates blocks" do + before do + @hotel_admin = Hotel::HotelAdmin.new + end + + #@block = Hotel::Block.new({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_amt: 5}) + + it "returns an error if block attempt has more than 5 rooms" do + proc{ @hotel_admin.create_block({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_amt: 6})}.must_raise ArgumentError + end + + it "returns an error if block attempt has more than 5 rooms" do + proc{ @hotel_admin.create_block({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_amt: 6})}.must_raise ArgumentError + end + + it "returns an error if block attempt has less than 1 room" do + proc{ @hotel_admin.create_block({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_amt: 0})}.must_raise ArgumentError + end + + it "throws an argument error for a bad end date" do + proc{ @hotel_admin.create_block({block_start_date: "2015-07-20", block_end_date: nil }) }.must_raise ArgumentError + end + + it "throws an argument error for a bad start date" do + proc{ @hotel_admin.create_block({block_start_date: nil, block_end_date: "2015-07-20", room_amt: 3 }) }.must_raise ArgumentError + end + + it "throws an argument error when end date isn't after start date" do + proc{ @hotel_admin.create_block({block_start_date: "2015-07-20", block_end_date: "2015-07-20", room_amt: 3 }) }.must_raise ArgumentError + proc{ @hotel_admin.create_block({block_start_date: "2015-07-21", block_end_date: "2015-07-20", room_amt: 3 }) }.must_raise ArgumentError + end + + it "can create a block of rooms" do + block_new = @hotel_admin.create_block({block_start_date: "2015-07-26", block_end_date: "2015-07-29", room_amt: 4}) + block_newb = @hotel_admin.create_block({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_amt: 3}) + block_new.must_be_instance_of Hash + @hotel_admin.blocks.must_be_instance_of Array + end + + + it "throws an argument error when there aren't enough rooms available" do + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 2})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 3})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 4})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 5})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 6})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 7})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 8})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 9})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 10})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 11})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 12})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 13})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 14})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 15})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 16})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 17})) + proc{ @hotel_admin.create_block({block_start_date: "2015-07-23", block_end_date: "2015-07-29", room_amt: 5}) }.must_raise ArgumentError + end + + + # + # it "only includes rooms that are available for the given date range" do + # + # end + # + # it "excludes rooms in the block for reservations by general public" do + # end + # + # it "can check whether a given block has any rooms available" do + # end + # + # it "can reserve a room from within a block of rooms" do + # end + + end end From 60231d0585059fc5318eec9873941172be7d9bf0 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Mon, 12 Mar 2018 08:28:09 -0700 Subject: [PATCH 36/43] add status to reservation class --- lib/reservation.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index e520125e8..a91af7e86 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -2,7 +2,7 @@ module Hotel class Reservation - attr_reader :checkin_date, :checkout_date, :room_id + attr_reader :checkin_date, :checkout_date, :room_id, :status def initialize(input) @@ -18,13 +18,17 @@ def initialize(input) @checkout_date = input[:checkout_date] @room_id = input[:room_id] @price_night = 200 - + @status = input[:status] end def price_night @price_night end + def status + @status + end + def calc_duration ((checkin_date...checkout_date).map{ |date| date}).count end From 74b830f47d1923ec4188ab3a9263a2398d17ce16 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Mon, 12 Mar 2018 08:28:50 -0700 Subject: [PATCH 37/43] update method for room holds, add appropriate tests --- lib/hotel_admin.rb | 40 ++++++++++++++++++++++++-- specs/hotel_admin_spec.rb | 60 ++++++++++++++++++++++++++------------- 2 files changed, 79 insertions(+), 21 deletions(-) diff --git a/lib/hotel_admin.rb b/lib/hotel_admin.rb index 0f9282a80..1ac26d48c 100644 --- a/lib/hotel_admin.rb +++ b/lib/hotel_admin.rb @@ -3,7 +3,7 @@ module Hotel class HotelAdmin - attr_reader :rooms, :reservations, :reservation, :block_start_date, :block_end_date, :room_amt, :blocks, :block + attr_reader :rooms, :reservations, :reservation, :block_start_date, :block_end_date, :room_amt, :blocks, :block, :rooms_held def initialize @rooms = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] @@ -75,12 +75,48 @@ def create_block(input) @block_start_date = input[:block_start_date] @block_end_date = input[:block_end_date] - @room_num = input[:room_amt] + @room_amt = input[:room_amt] @blocks << input @block = input + @holds_reservations = [] + @rooms_held = [] + input[:room_amt].times do |i| + avail_room = view_available_rooms(input[:block_start_date], input[:block_end_date])[0] + new_res = add_reservation(Hotel::Reservation.new({checkin_date: input[:block_start_date], checkout_date: input[:block_end_date], room_id: avail_room, status: "held"})) + @rooms_held << avail_room + @holds_reservations << new_res + end return @block end + def return_blocks_rooms(input) + @rooms_held + end + + def check_block_availability(input) + arr_available_held_rooms = [] + @holds_reservations + #arr_available_held_rooms = + @holds_reservations.each do |res| + if res.status == "held" + arr_available_held_rooms << res + end + end + #puts arr_available_held_rooms + return arr_available_held_rooms + + end + + # + # def reserve_room_in_block(input) + # puts puts + # print "reserve_room_in_block: " + # @holds_reservations.each do |res| + # puts check_block_availability(input) + # puts + # puts "End of reserve_room_in_block" + # puts puts + # end end end diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb index 9e4bd818d..d80a4899a 100644 --- a/specs/hotel_admin_spec.rb +++ b/specs/hotel_admin_spec.rb @@ -108,14 +108,6 @@ proc{ @hotel_admin.create_block({block_start_date: "2015-07-21", block_end_date: "2015-07-20", room_amt: 3 }) }.must_raise ArgumentError end - it "can create a block of rooms" do - block_new = @hotel_admin.create_block({block_start_date: "2015-07-26", block_end_date: "2015-07-29", room_amt: 4}) - block_newb = @hotel_admin.create_block({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_amt: 3}) - block_new.must_be_instance_of Hash - @hotel_admin.blocks.must_be_instance_of Array - end - - it "throws an argument error when there aren't enough rooms available" do @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1})) @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 2})) @@ -137,20 +129,50 @@ proc{ @hotel_admin.create_block({block_start_date: "2015-07-23", block_end_date: "2015-07-29", room_amt: 5}) }.must_raise ArgumentError end + it "can create a block of rooms" do + block_new = @hotel_admin.create_block({block_start_date: "2015-07-26", block_end_date: "2015-07-29", room_amt: 4}) + @hotel_admin.create_block({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_amt: 3}) + block_new.must_be_instance_of Hash + block_new[:room_amt].must_be_instance_of Integer + block_new[:block_start_date].must_equal "2015-07-26" + @hotel_admin.blocks.must_be_instance_of Array + @hotel_admin.blocks.count.must_equal 2 + end + + it "excludes rooms in the block for reservations by general public" do + @hotel_admin.create_block({block_start_date: "2015-07-26", block_end_date: "2015-07-29", room_amt: 5}) + new_res = @hotel_admin.reserve_available_room("2015-07-26", "2015-07-27") + new_res.room_id.must_equal 6 + end + + it "can check whether a given block has any rooms available" do + new_hold = @hotel_admin.create_block({block_start_date: "2015-07-26", block_end_date: "2015-07-29", room_amt: 5}) + @hotel_admin.check_block_availability(new_hold).must_be_instance_of Array + + # @hotel_admin.check_block_availability(new_hold).each do |status| + # puts @hotel_admin.reservation.status + # end + end - # - # it "only includes rooms that are available for the given date range" do - # - # end - # - # it "excludes rooms in the block for reservations by general public" do - # end - # - # it "can check whether a given block has any rooms available" do - # end - # # it "can reserve a room from within a block of rooms" do + # new_hold = @hotel_admin.create_block({block_start_date: "2015-07-26", block_end_date: "2015-07-29", room_amt: 5}) + # @hotel_admin.reserve_room_in_block(new_hold) # end end + + describe "return_blocks_rooms method" do + before do + @hotel_admin = Hotel::HotelAdmin.new + end + + it "only includes rooms that are available for the given date range" do + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 1})) + @hotel_admin.add_reservation(Hotel::Reservation.new({checkin_date: "2015-07-20", checkout_date: "2015-07-25", room_id: 2})) + new_hold = @hotel_admin.create_block({block_start_date: "2015-07-23", block_end_date: "2015-07-29", room_amt: 5}) + @hotel_admin.return_blocks_rooms(new_hold).count.must_equal 5 + @hotel_admin.return_blocks_rooms(new_hold).must_equal [3, 4, 5, 6, 7] + end + end + end From d217828bad0753b2cd252f6896ea5aa343c32469 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Tue, 13 Mar 2018 18:30:45 -0700 Subject: [PATCH 38/43] removed unncessary status and price_night methods --- lib/reservation.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index a91af7e86..8c8989dd2 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -2,7 +2,7 @@ module Hotel class Reservation - attr_reader :checkin_date, :checkout_date, :room_id, :status + attr_reader :checkin_date, :checkout_date, :room_id, :status, :price_night def initialize(input) @@ -21,14 +21,6 @@ def initialize(input) @status = input[:status] end - def price_night - @price_night - end - - def status - @status - end - def calc_duration ((checkin_date...checkout_date).map{ |date| date}).count end From d2e68c946cb14796a6042e392946a08f5488e187 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Tue, 13 Mar 2018 18:42:46 -0700 Subject: [PATCH 39/43] added missing comma --- lib/reservation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 8c8989dd2..2a226c6b4 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -2,7 +2,7 @@ module Hotel class Reservation - attr_reader :checkin_date, :checkout_date, :room_id, :status, :price_night + attr_reader :checkin_date, :checkout_date, :room_id, :status , :price_night def initialize(input) From f728d7dbbc846bd7f4c0218bb64184ad9f26619d Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Tue, 13 Mar 2018 23:55:31 -0700 Subject: [PATCH 40/43] added party_name to reservations class --- lib/reservation.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 2a226c6b4..4476a689a 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -2,7 +2,7 @@ module Hotel class Reservation - attr_reader :checkin_date, :checkout_date, :room_id, :status , :price_night + attr_reader :checkin_date, :checkout_date, :room_id, :status, :price_night, :party_name def initialize(input) @@ -19,6 +19,7 @@ def initialize(input) @room_id = input[:room_id] @price_night = 200 @status = input[:status] + @party_name = input[:group_name] end def calc_duration From f8ac9ef9de406bcbabb1ddc5446be78da41196a4 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Wed, 14 Mar 2018 01:04:32 -0700 Subject: [PATCH 41/43] tried to update status --- lib/reservation.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 4476a689a..ecae74706 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -2,7 +2,8 @@ module Hotel class Reservation - attr_reader :checkin_date, :checkout_date, :room_id, :status, :price_night, :party_name + attr_reader :checkin_date, :checkout_date, :room_id, :price_night, :party_name + attr_accessor :status def initialize(input) @@ -22,6 +23,10 @@ def initialize(input) @party_name = input[:group_name] end + def status + return @status + end + def calc_duration ((checkin_date...checkout_date).map{ |date| date}).count end From 6c512e05afa7e3ffcc189257858a5b8d496b6ae0 Mon Sep 17 00:00:00 2001 From: CheerOnMars Date: Wed, 14 Mar 2018 01:06:53 -0700 Subject: [PATCH 42/43] tried to update method and tests to reserve a room in a block --- lib/hotel_admin.rb | 38 ++++++++++++++++---------------------- specs/hotel_admin_spec.rb | 20 ++++++++++---------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/lib/hotel_admin.rb b/lib/hotel_admin.rb index 1ac26d48c..95468023a 100644 --- a/lib/hotel_admin.rb +++ b/lib/hotel_admin.rb @@ -3,12 +3,15 @@ module Hotel class HotelAdmin - attr_reader :rooms, :reservations, :reservation, :block_start_date, :block_end_date, :room_amt, :blocks, :block, :rooms_held + attr_reader :rooms, :reservations, :reservation, :block_start_date, :block_end_date, :room_amt, :blocks, :block, :rooms_held, :block_name + attr_accessor :status def initialize @rooms = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] @reservations = [] @blocks = [] + @holds_reservations = [] + @rooms_held = [] end def add_reservation(reservation) @@ -50,7 +53,6 @@ def reserve_available_room(checkin_request, checkout_request) add_reservation(Hotel::Reservation.new({checkin_date: checkin_request, checkout_date: checkout_request, room_id: avail_room})) end - def create_block(input) if input[:block_start_date] == nil || input[:block_end_date] == nil @@ -72,17 +74,15 @@ def create_block(input) if input[:room_amt] > view_available_rooms(input[:block_start_date], input[:block_end_date]).count raise ArgumentError.new("There are not enough rooms available during that time.") end - @block_start_date = input[:block_start_date] @block_end_date = input[:block_end_date] @room_amt = input[:room_amt] + @block_name = input[:group_name] @blocks << input @block = input - @holds_reservations = [] - @rooms_held = [] input[:room_amt].times do |i| avail_room = view_available_rooms(input[:block_start_date], input[:block_end_date])[0] - new_res = add_reservation(Hotel::Reservation.new({checkin_date: input[:block_start_date], checkout_date: input[:block_end_date], room_id: avail_room, status: "held"})) + new_res = add_reservation(Hotel::Reservation.new({checkin_date: input[:block_start_date], checkout_date: input[:block_end_date], room_id: avail_room, status: "held", group_name: input[:group_name]})) @rooms_held << avail_room @holds_reservations << new_res end @@ -93,30 +93,24 @@ def return_blocks_rooms(input) @rooms_held end - def check_block_availability(input) + def return_held_reservations + @holds_reservations + end + + def check_block_availability(group_name) arr_available_held_rooms = [] @holds_reservations - #arr_available_held_rooms = @holds_reservations.each do |res| - if res.status == "held" + if res.status == "held" && res.party_name == group_name arr_available_held_rooms << res end end - #puts arr_available_held_rooms return arr_available_held_rooms - end - # - # def reserve_room_in_block(input) - # puts puts - # print "reserve_room_in_block: " - # @holds_reservations.each do |res| - # puts check_block_availability(input) - # puts - # puts "End of reserve_room_in_block" - # puts puts - # end - + def reserve_room_in_block(group_name) + block_res = check_block_availability(group_name)[0] + block_res.status = "booked" + end end end diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb index d80a4899a..0e095becf 100644 --- a/specs/hotel_admin_spec.rb +++ b/specs/hotel_admin_spec.rb @@ -146,18 +146,18 @@ end it "can check whether a given block has any rooms available" do - new_hold = @hotel_admin.create_block({block_start_date: "2015-07-26", block_end_date: "2015-07-29", room_amt: 5}) - @hotel_admin.check_block_availability(new_hold).must_be_instance_of Array - - # @hotel_admin.check_block_availability(new_hold).each do |status| - # puts @hotel_admin.reservation.status - # end + @hotel_admin.create_block({block_start_date: "2015-09-20", block_end_date: "2015-09-25", room_amt: 4, group_name: "Prince"}) + @hotel_admin.check_block_availability("Prince").must_be_instance_of Array + @hotel_admin.check_block_availability("Prince").length.must_equal 4 end - # it "can reserve a room from within a block of rooms" do - # new_hold = @hotel_admin.create_block({block_start_date: "2015-07-26", block_end_date: "2015-07-29", room_amt: 5}) - # @hotel_admin.reserve_room_in_block(new_hold) - # end + it "can reserve a room from within a block of rooms" do + new_hold = @hotel_admin.create_block({block_start_date: "2015-07-26", block_end_date: "2015-07-29", room_amt: 5, group_name: "Bowie"}) + block_res = @hotel_admin.reserve_room_in_block("Bowie") + puts "XXXXXXXXXxxxxxxxxxx block_res xxxxxxxxxxXXXXXXXXX" + block_res.class.must_be_kind_of Hotel::Reservation + block_res.status.must_equal "booked" + end end From 256953b83d932e6c461f497cfee24b1220a26696 Mon Sep 17 00:00:00 2001 From: Cheeron Mars Date: Mon, 2 Apr 2018 12:31:06 -0700 Subject: [PATCH 43/43] corrected design-activity --- .DS_Store | Bin 0 -> 6148 bytes design-activity.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 .DS_Store create mode 100644 design-activity.md diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..99d10a17693d4573349ae7ded8bb5792b4eeccbe GIT binary patch literal 6148 zcmeHKOHRWu5PeRAC}PtcEOP>+uDXq?aDrX{wM8vbqgHCO&l$KH5^HuWxdLzOA&T?a zB7|ln`#JORWS)~a2H=*}b`Hz{OxXmJ8+HRCc4<9HR3pJo<~Z!;tIe@I^*l}SR~eAC zOYwjmUT}%l&lR%hjjcQu#kRU^fcMX@S6@!cwjH&d_N`|ksU`6GCm;5xu#U1KS@%5# za(Ct^kG(tSctrQ%pLa}fVAY-ccW=zEmVvyDrI$}Fah{x$;RoX4j97W^zh*{v(pob^VvCn=H21)fYuuW z#z4%#BwWs9|9>1m|HnagWegYt|B3;Z7OP^(l5}tF6(@Ub#`eS}B7SwiCWHgO71LL? d;(InP)Mqjv=8APdYAE(2;AybV82D8Nz5%V3dhGxJ literal 0 HcmV?d00001 diff --git a/design-activity.md b/design-activity.md new file mode 100644 index 000000000..cef5c40bc --- /dev/null +++ b/design-activity.md @@ -0,0 +1,43 @@ + +###Questions + +- What classes does each implementation include? Are the lists the same? + - Both implementations have CartEntry, ShoppingCart, and Order. The lists are the same. + +- Write down a sentence to describe each class. + - The CartEntry class initializes the item in the cart using a unit price and quantity. In implementation b, it also defines the price. + - The ShoppingCart class initializes the cart using the collection of entries In implementation b, it also defines the price. + - The Order class initializes the order and defines the method of finding the total price. + + +- How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper. + + +- What **data** does each class store? How (if at all) does this differ between the two implementations? + - CartEntry, ShoppingCart, and Order each has the initialize method. Order also has the total_price method. + - In implementation B, CartEntry and ShoppingCart also have a price method. + + +- What **methods** does each class have? How (if at all) does this differ between the two implementations? +- CartEntry has unit_price, quantity. ShoppingCart stores entries. Order stores total_price and cart. +- In implementation B, CartEntry and ShoppingCart also store price. + + +- Consider the `Order#total_price` method. In each implementation: + - Is logic to compute the price delegated to "lower level" classes like `ShoppingCart` and `CartEntry`, or is it retained in `Order`? + + + - Does `total_price` directly manipulate the instance variables of other classes? + + +- If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify? + + +- Which implementation better adheres to the single responsibility principle? + + +- Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? + + + + Based on the answers to 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.