From 92b2c28d1c960f8bb09efd1d62f0e0442a8b36ab Mon Sep 17 00:00:00 2001 From: Mariko Date: Wed, 7 Mar 2018 16:17:47 -0800 Subject: [PATCH 1/5] updated method names and bug fixes --- Rakefile | 9 +++++ lib/reception.rb | 80 +++++++++++++++++++++++++++++++++++++++ lib/reservation.rb | 45 ++++++++++++++++++++++ specs/reception_spec.rb | 56 +++++++++++++++++++++++++++ specs/reservation_spec.rb | 32 ++++++++++++++++ specs/spec_helper.rb | 15 ++++++++ 6 files changed, 237 insertions(+) create mode 100644 Rakefile create mode 100644 lib/reception.rb create mode 100644 lib/reservation.rb create mode 100644 specs/reception_spec.rb create mode 100644 specs/reservation_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/reception.rb b/lib/reception.rb new file mode 100644 index 000000000..3025db353 --- /dev/null +++ b/lib/reception.rb @@ -0,0 +1,80 @@ +require_relative 'reservation' +require 'pry' +require 'date' + +module Hotel + class Reception + attr_reader :reservation_list + def initialize + @reservation_list = [] + end + + +# Adds new resercation to reservations array + def add_reservation(check_in, check_out) + new_reservation = Hotel::Reservation.new(check_in, check_out) + if check_in >= check_out + raise ArgumentError.new "invalid date range" + end + @reservation_list << new_reservation + return @reservation_list + end + +# Searches through reservatsions to generate reservations for a given day + def reservations_by_date(date) + reservations_on_date = [] + @reservation_list.each do |reservation| + if reservation.date_range.include? date + reservations_on_date << reservation + end + end + # + # # if reservations_on_date.empty? + # return "All rooms available for #{date}" + # # end + return reservations_on_date + end + + # def availability_by_date(date) + # booked_rooms_on_date = [] + # + # resercations_by_date(date).each do |reservation| + # booked_rooms_on_date << @assigned_room + # end + # + # if booked_rooms_on_date.empty? + # raise ArgumentError.new "No rooms available on #{date}" + # end + # return booked_rooms_on_date + # end + + def availability_by_date_range(check_in, check_out) + occupied_rooms = [] + range = (check_in...check_out).to_a + @reservation_list.each do |reservation| + if (range.include? reservation.check_in) || (range.include? reservation.check_out - 1) + occupied_rooms << reservation.assigned_room + end + end + + available_rooms = [] + ROOMS.each do |room| + if !(occupied_rooms.include? room) + available_rooms << room + end + end + return available_rooms + end + + # def room_status(date, room) + # availability = "" + # if availability_by_date(date).availability_on_date.include? room + # availability = "Available" + # else + # availability = "Booked" + # end + # return availability + # end + + end +end diff --git a/lib/reservation.rb b/lib/reservation.rb new file mode 100644 index 000000000..dd87e3443 --- /dev/null +++ b/lib/reservation.rb @@ -0,0 +1,45 @@ +# require_relative 'reception' +require 'pry' +require 'date' + +module Hotel + COST = 200 + ROOMS = Array(1..20) + class Reservation + + attr_reader :check_in, :check_out, :assigned_room + + def initialize(check_in, check_out) + + @check_in = check_in + @check_out = check_out + @range = date_range + @length_of_stay = @range.length + @assigned_room = assign_room + @total_cost = total_cost + end + +# Randomly assigns room + def assign_room + assigned_room = ROOMS.sample + return assigned_room + end + +# Creates array of dates from given check_in and check_out dates + def date_range + @range = (@check_in...@check_out).to_a + return @range + end + + + def length_of_stay + nights = (@check_out - @check_in).to_i + return nights + end + + def total_cost + total_cost = (COST * length_of_stay).to_f.round(2) + return total_cost + end + end +end diff --git a/specs/reception_spec.rb b/specs/reception_spec.rb new file mode 100644 index 000000000..4fd29d793 --- /dev/null +++ b/specs/reception_spec.rb @@ -0,0 +1,56 @@ + +require_relative 'spec_helper' +require 'pry' + +describe 'Reception class' do + before do + @receptionist = Hotel::Reception.new + @add_reservation = @receptionist.add_reservation(Date.new(2018,3,5), Date.new(2018,3,10)) + end + + it 'creates a new instance of Reception' do + @receptionist.must_be_instance_of Hotel::Reception + end + + it "returns an array of all reservations" do + @receptionist.reservation_list.must_be_kind_of Array + + @add_reservation.length.must_equal 1 + end + + it "raises an error when date range is invalid" do + proc {@receptionist.add_reservation(Date.new(2018,3,11), Date.new(2018,3,5))}.must_raise ArgumentError + end + + it 'reservation_by_date' do + @receptionist.reservations_by_date(Date.new(2018,3,8)).length.must_equal 1 + @receptionist.reservations_by_date(Date.new(2018,3,6)).length.must_equal 1 + end + + it 'retruns an empty array when no reservations on given date' do + @receptionist.reservations_by_date(Date.new(2018,3,16)).must_equal [] + @receptionist.reservations_by_date(Date.new(2018,3,16)).must_be_empty + end + # + # it "returns availability of room" do + # @receptionist.room_status((Date.new(2018,3,11)),1).must_equal "Available" + # end + + # it "returns an array of available rooms for a given day" do + # @receptionist.availability_by_date(Date.new(2018,3,8)).must_be_kind_of Array + # @receptionist.availability_by_date(Date.new(2018,3,8)).length.must_equal 1 + # end + + it "returns an array of all available rooms for given range" do + @receptionist.availability_by_date_range(Date.new(2018,3,5), Date.new(2018,3,10)).length.must_equal 19 + end + + it "returns an empty array if no rooms available for a given date range" do + 20.times do + @receptionist.add_reservation(Date.new(2018,3,5), Date.new(2018,3,10)) + end + + @receptionist.availability_by_date_range(Date.new(2018,3,5), Date.new(2018,3,10)).must_equal [] + @receptionist.availability_by_date_range(Date.new(2018,3,5), Date.new(2018,3,10)).must_be_empty + end +end diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb new file mode 100644 index 000000000..f2deb4762 --- /dev/null +++ b/specs/reservation_spec.rb @@ -0,0 +1,32 @@ +require_relative 'spec_helper' +require 'pry' + +describe 'Reservation class' do + + before do + @new_reservation = Hotel::Reservation.new(Date.new(2018,3,5), Date.new(2018,3,10)) + + @room = @new_reservation.assign_room + end + + it "creates a new instance of Reservation" do + @new_reservation.must_be_instance_of Hotel::Reservation + end + + it "assigns a valid room" do + Hotel::ROOMS.must_include @room + end + + it "calculates number of nights" do + @new_reservation.length_of_stay.must_be_kind_of Integer + + @new_reservation.length_of_stay.must_equal 5 + end + + it "calculatesthe total cost of stay" do + @new_reservation.total_cost.must_be_kind_of Float + + @new_reservation.total_cost.must_be_within_delta 1000, 0.5 + end + +end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb new file mode 100644 index 000000000..0fb7cde1e --- /dev/null +++ b/specs/spec_helper.rb @@ -0,0 +1,15 @@ +require 'time' + +require 'simplecov' +SimpleCov.start + +require 'minitest' +require 'minitest/autorun' +require 'minitest/reporters' +# Add simplecov + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new + +# Require_relative your lib files here! +require_relative '../lib/reservation' +require_relative '../lib/reception' From 50a09338ed388045fd4f0fe2cde570cc56152765 Mon Sep 17 00:00:00 2001 From: Mariko Date: Thu, 8 Mar 2018 09:04:34 -0800 Subject: [PATCH 2/5] Room is assigned based on available room, wave 2 complete --- .DS_Store | Bin 0 -> 8196 bytes lib/reception.rb | 42 +++++++++------------------------- lib/reservation.rb | 13 +++-------- specs/reception_spec.rb | 46 +++++++++++++++++--------------------- specs/reservation_spec.rb | 4 ++-- 5 files changed, 36 insertions(+), 69 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1dcc9a0987b6ef151dec4bf408fd2183a977fe7c GIT binary patch literal 8196 zcmeI1Piz%M9LImZ(!%UQ=@x-@fd?-%NQM4+ltL{5d9)?8QZ2Ei|0tAwZ`XF?cK7ji z-)o`NREcsipx(fP#CT9^;;9!es0aT96Cr8*!@+}IJQ|HAp7b{}`x@w;oy>axfGs(54?raVFuJ(aR#Ub_;(mTDN=0E!Fw#>dSy-^-15Gn9bD!{)Fak{uohIU$7@#&yU90ADk zBY;R$rgMOZiH9~B+G%M;C_Pi29xx2W@Q8sjocwX#oNO|*)6&XtKp74g_Ke{P1x4=^ z7Z=R|lhQ_cq(G#=Vg>l?!ypYFvWpKNMM)WjS2?w^`cSjCP#hdR!Voxd=7 zaq9VNa&8!YAE0c(T(2)RQOD1>%83@eUYO{&g^4QaYQ4QfJwB|h%hUL~GJ);6ey^4F z$qs8}KFzr!?YSqi7Wen1JtsHj`omgz+Hlf2#|W$=j?-;lu>AhOnh1Dl(D$-It7tf^ zX*u6|#-et1-fE-Pe!oqRwyadG)^{nI!FqfewXCUC>lMvc zdY+?o6*YQ;+Q>9hIq4WF%aK)0YBST0D}8yXrmS429%4#=+8Z0AN&2GO!%1B~!@KP? z{GcmixiqBDsqfN?%8hL_qyg?bVw!wFtSVV87hPzeR3#H30}OPiqm85;h6wTuT!L5N z3S5OZ;BEK-X5l7$24BKga2xKxUHAchf?wcQ_zixCKat@EtiVdtaXZ#wJtnXj58y#O zge`a+JMn4k!X7-0XYec# zcf=Is9{~6k%)p26DcmCPzJ~ANNB9~3Am~c4jG)tT3&wCO?!;=`g}bp9_hVCt-%&h< z9rz?6*n_>;j{`V}X|xEyQM55j0OoNVC-4P)5ib#nSMVyK_!?fvH}QrfY#zM!khsv` zyHr>NUcNi)I-Wa1z5=lKhedY}ngT22fGhd=|LF3+|37HcipCo$5Gn9C6u{!P?zR>R zSnk8l&)RXi&eFvbZ#ONi2%(HO;q~G;PImqeLn_BZUoy1Q(vpYLzy3o&wEy1_!b7zG JOC280{4ZlF;Vb|E literal 0 HcmV?d00001 diff --git a/lib/reception.rb b/lib/reception.rb index 3025db353..95016e5fd 100644 --- a/lib/reception.rb +++ b/lib/reception.rb @@ -4,18 +4,22 @@ module Hotel class Reception - attr_reader :reservation_list + attr_reader :reservation_list#, :assigned_room def initialize @reservation_list = [] + # @assigned_room = assign_room end - -# Adds new resercation to reservations array +# Checks for availabl rooms, assigns room to new_reservation and adds new reservation to reservations array def add_reservation(check_in, check_out) - new_reservation = Hotel::Reservation.new(check_in, check_out) + + available_room = availability_by_date_range(check_in, check_out).first + + new_reservation = Hotel::Reservation.new(check_in, check_out, available_room) if check_in >= check_out raise ArgumentError.new "invalid date range" end + # assign_room(check_in, check_out) @reservation_list << new_reservation return @reservation_list end @@ -28,29 +32,13 @@ def reservations_by_date(date) reservations_on_date << reservation end end - # - # # if reservations_on_date.empty? - # return "All rooms available for #{date}" - # # end return reservations_on_date end - # def availability_by_date(date) - # booked_rooms_on_date = [] - # - # resercations_by_date(date).each do |reservation| - # booked_rooms_on_date << @assigned_room - # end - # - # if booked_rooms_on_date.empty? - # raise ArgumentError.new "No rooms available on #{date}" - # end - # return booked_rooms_on_date - # end - +# compares each reservation to date range in question and returns an array of rooms available for the given period. def availability_by_date_range(check_in, check_out) occupied_rooms = [] - range = (check_in...check_out).to_a + range = (check_in...check_out)#.to_a @reservation_list.each do |reservation| if (range.include? reservation.check_in) || (range.include? reservation.check_out - 1) occupied_rooms << reservation.assigned_room @@ -66,15 +54,5 @@ def availability_by_date_range(check_in, check_out) return available_rooms end - # def room_status(date, room) - # availability = "" - # if availability_by_date(date).availability_on_date.include? room - # availability = "Available" - # else - # availability = "Booked" - # end - # return availability - # end - end end diff --git a/lib/reservation.rb b/lib/reservation.rb index dd87e3443..184ca95aa 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -6,32 +6,25 @@ module Hotel COST = 200 ROOMS = Array(1..20) class Reservation - + attr_reader :check_in, :check_out, :assigned_room - def initialize(check_in, check_out) + def initialize(check_in, check_out, assigned_room) @check_in = check_in @check_out = check_out + @assigned_room = assigned_room @range = date_range @length_of_stay = @range.length - @assigned_room = assign_room @total_cost = total_cost end -# Randomly assigns room - def assign_room - assigned_room = ROOMS.sample - return assigned_room - end - # Creates array of dates from given check_in and check_out dates def date_range @range = (@check_in...@check_out).to_a return @range end - def length_of_stay nights = (@check_out - @check_in).to_i return nights diff --git a/specs/reception_spec.rb b/specs/reception_spec.rb index 4fd29d793..644cefcab 100644 --- a/specs/reception_spec.rb +++ b/specs/reception_spec.rb @@ -7,39 +7,35 @@ @receptionist = Hotel::Reception.new @add_reservation = @receptionist.add_reservation(Date.new(2018,3,5), Date.new(2018,3,10)) end - - it 'creates a new instance of Reception' do - @receptionist.must_be_instance_of Hotel::Reception + describe "initialize" do + it 'creates a new instance of Reception' do + @receptionist.must_be_instance_of Hotel::Reception + end end - it "returns an array of all reservations" do - @receptionist.reservation_list.must_be_kind_of Array + describe "add_reservation" do + it "returns an array of all reservations" do + @receptionist.reservation_list.must_be_kind_of Array - @add_reservation.length.must_equal 1 - end + @add_reservation.length.must_equal 1 + end - it "raises an error when date range is invalid" do - proc {@receptionist.add_reservation(Date.new(2018,3,11), Date.new(2018,3,5))}.must_raise ArgumentError + it "raises an error when date range is invalid" do + proc {@receptionist.add_reservation(Date.new(2018,3,11), Date.new(2018,3,5))}.must_raise ArgumentError + end end - it 'reservation_by_date' do - @receptionist.reservations_by_date(Date.new(2018,3,8)).length.must_equal 1 - @receptionist.reservations_by_date(Date.new(2018,3,6)).length.must_equal 1 - end + describe 'reservation_by_date' do + it "returns the number of reservations for given day" do + @receptionist.reservations_by_date(Date.new(2018,3,8)).length.must_equal 1 + @receptionist.reservations_by_date(Date.new(2018,3,6)).length.must_equal 1 + end - it 'retruns an empty array when no reservations on given date' do - @receptionist.reservations_by_date(Date.new(2018,3,16)).must_equal [] - @receptionist.reservations_by_date(Date.new(2018,3,16)).must_be_empty + it 'retruns an empty array when no reservations on given date' do + @receptionist.reservations_by_date(Date.new(2018,3,16)).must_equal [] + @receptionist.reservations_by_date(Date.new(2018,3,16)).must_be_empty + end end - # - # it "returns availability of room" do - # @receptionist.room_status((Date.new(2018,3,11)),1).must_equal "Available" - # end - - # it "returns an array of available rooms for a given day" do - # @receptionist.availability_by_date(Date.new(2018,3,8)).must_be_kind_of Array - # @receptionist.availability_by_date(Date.new(2018,3,8)).length.must_equal 1 - # end it "returns an array of all available rooms for given range" do @receptionist.availability_by_date_range(Date.new(2018,3,5), Date.new(2018,3,10)).length.must_equal 19 diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index f2deb4762..6561716a9 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -4,9 +4,9 @@ describe 'Reservation class' do before do - @new_reservation = Hotel::Reservation.new(Date.new(2018,3,5), Date.new(2018,3,10)) + @new_reservation = Hotel::Reservation.new(Date.new(2018,3,5), Date.new(2018,3,10), 1) - @room = @new_reservation.assign_room + @room = @new_reservation.assigned_room end it "creates a new instance of Reservation" do From 87918f6caf174f219813157bf1e53a44eaee614e Mon Sep 17 00:00:00 2001 From: Mariko Date: Mon, 12 Mar 2018 12:34:26 -0700 Subject: [PATCH 3/5] Added block class and block spec --- lib/block.rb | 13 +++++++++++ lib/reception.rb | 15 +++++++----- specs/block_spec.rb | 19 +++++++++++++++ specs/reception_spec.rb | 49 +++++++++++++++++++++++++++++++-------- specs/reservation_spec.rb | 10 +++++++- 5 files changed, 89 insertions(+), 17 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..3dac95eeb --- /dev/null +++ b/lib/block.rb @@ -0,0 +1,13 @@ +# require_relative 'reception' + +require 'pry' +require 'date' + +module Hotel + class Block < reception + + def initialize + + end + end +end diff --git a/lib/reception.rb b/lib/reception.rb index 95016e5fd..6754b38ec 100644 --- a/lib/reception.rb +++ b/lib/reception.rb @@ -4,24 +4,23 @@ module Hotel class Reception - attr_reader :reservation_list#, :assigned_room + attr_reader :reservation_list def initialize @reservation_list = [] - # @assigned_room = assign_room end # Checks for availabl rooms, assigns room to new_reservation and adds new reservation to reservations array def add_reservation(check_in, check_out) - available_room = availability_by_date_range(check_in, check_out).first + assigned_room = availability_by_date_range(check_in, check_out).first - new_reservation = Hotel::Reservation.new(check_in, check_out, available_room) + new_reservation = Hotel::Reservation.new(check_in, check_out, assigned_room) if check_in >= check_out raise ArgumentError.new "invalid date range" end - # assign_room(check_in, check_out) + @reservation_list << new_reservation - return @reservation_list + return new_reservation end # Searches through reservatsions to generate reservations for a given day @@ -54,5 +53,9 @@ def availability_by_date_range(check_in, check_out) return available_rooms end +# # Creates room blocks based on availability_by_date_range +# def room_block +# +# end end end diff --git a/specs/block_spec.rb b/specs/block_spec.rb new file mode 100644 index 000000000..ea1c13dc2 --- /dev/null +++ b/specs/block_spec.rb @@ -0,0 +1,19 @@ +require_relative 'spec_helper' +require 'pry' + +describe 'Bock class' do + + describe "room_block" do + it "returns an array with the requeted number of rooms" do + + end + + it "it gives a discoutnd price for reservation" do + + end + + it "it can only be reserved through the block request" do + + end + end +end diff --git a/specs/reception_spec.rb b/specs/reception_spec.rb index 644cefcab..9af368334 100644 --- a/specs/reception_spec.rb +++ b/specs/reception_spec.rb @@ -5,8 +5,11 @@ describe 'Reception class' do before do @receptionist = Hotel::Reception.new - @add_reservation = @receptionist.add_reservation(Date.new(2018,3,5), Date.new(2018,3,10)) + @new_reservation = @receptionist.add_reservation(Date.new(2018,3,5), Date.new(2018,3,10)) end + + # ***IDEAS*** validate_date check for calendar date, check for date after today, check for valid date_range + describe "initialize" do it 'creates a new instance of Reception' do @receptionist.must_be_instance_of Hotel::Reception @@ -16,8 +19,10 @@ describe "add_reservation" do it "returns an array of all reservations" do @receptionist.reservation_list.must_be_kind_of Array + end - @add_reservation.length.must_equal 1 + it "assaigns an available room" do + @new_reservation.assigned_room.must_equal 1 end it "raises an error when date range is invalid" do @@ -29,24 +34,48 @@ it "returns the number of reservations for given day" do @receptionist.reservations_by_date(Date.new(2018,3,8)).length.must_equal 1 @receptionist.reservations_by_date(Date.new(2018,3,6)).length.must_equal 1 + + 4.times do + @receptionist.add_reservation(Date.new(2018,3,5), Date.new(2018,3,10)) + end + @receptionist.reservations_by_date(Date.new(2018,3,6)).length.must_equal 5 + + 15.times do + @receptionist.add_reservation(Date.new(2018,3,5), Date.new(2018,3,10)) + end + @receptionist.reservations_by_date(Date.new(2018,3,6)).length.must_equal 20 end it 'retruns an empty array when no reservations on given date' do @receptionist.reservations_by_date(Date.new(2018,3,16)).must_equal [] @receptionist.reservations_by_date(Date.new(2018,3,16)).must_be_empty + @receptionist.reservations_by_date(Date.new(2018,3,4)).must_be_empty end end - it "returns an array of all available rooms for given range" do - @receptionist.availability_by_date_range(Date.new(2018,3,5), Date.new(2018,3,10)).length.must_equal 19 - end + describe "availability_by_date_range" do + it "returns an array of all available rooms for given range" do + @receptionist.availability_by_date_range(Date.new(2018,3,5), Date.new(2018,3,10)).length.must_equal 19 - it "returns an empty array if no rooms available for a given date range" do - 20.times do - @receptionist.add_reservation(Date.new(2018,3,5), Date.new(2018,3,10)) + 4.times do + @receptionist.add_reservation(Date.new(2018,3,5), Date.new(2018,3,10)) + end + @receptionist.availability_by_date_range(Date.new(2018,3,5), Date.new(2018,3,10)).length.must_equal 15 + + end + + it "returns an empty array if no rooms available for a given date range" do + 20.times do + @receptionist.add_reservation(Date.new(2018,3,5), Date.new(2018,3,10)) + end + + @receptionist.availability_by_date_range(Date.new(2018,3,5), Date.new(2018,3,10)).must_equal [] + @receptionist.availability_by_date_range(Date.new(2018,3,5), Date.new(2018,3,10)).must_be_empty end - @receptionist.availability_by_date_range(Date.new(2018,3,5), Date.new(2018,3,10)).must_equal [] - @receptionist.availability_by_date_range(Date.new(2018,3,5), Date.new(2018,3,10)).must_be_empty + it "will return array of all rooms if no bookings during given range" do + @receptionist.availability_by_date_range(Date.new(2018,3,11), Date.new(2018,3,21)).length.must_equal 20 + end end + end diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 6561716a9..f86b9baab 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -19,10 +19,18 @@ it "calculates number of nights" do @new_reservation.length_of_stay.must_be_kind_of Integer - @new_reservation.length_of_stay.must_equal 5 + + Hotel::Reservation.new(Date.new(2018,3,2), Date.new(2018,3,10), 1).length_of_stay.must_equal 8 + + # Hotel::Reservation.new(Date.new(2018,3,2), Date.new(2018,3,2), 1).length_of_stay.must_equal 0 end + describe "date_range" do + it "calculates accurate date range" do + @new_reservation.date_range.must_be_kind_of Array + end + end it "calculatesthe total cost of stay" do @new_reservation.total_cost.must_be_kind_of Float From f1073435d2db21e197bfb0aa7d27ad92a0c2f4a2 Mon Sep 17 00:00:00 2001 From: Mariko Date: Mon, 12 Mar 2018 12:35:09 -0700 Subject: [PATCH 4/5] updated block class --- lib/block.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index 3dac95eeb..7b2c99988 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -1,12 +1,23 @@ -# require_relative 'reception' + require_relative 'reception' require 'pry' require 'date' +# block is-a reception item +# block inherits from reception + module Hotel - class Block < reception + class Block < Reception + + def initialize(check_in, check_out, number_of_rooms) + @check_in = check_in + @check_out = check_out + @number_of_rooms = number_of_rooms + + availability_by_date_range(check_in, check_out) + end - def initialize + def hold_block end end From c718c7d4d87a15d64270b5c593780352b29ae27e Mon Sep 17 00:00:00 2001 From: Mariko Date: Sun, 1 Apr 2018 16:37:55 -0700 Subject: [PATCH 5/5] design-activity --- design-activity.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 design-activity.md diff --git a/design-activity.md b/design-activity.md new file mode 100644 index 000000000..7e57f49b0 --- /dev/null +++ b/design-activity.md @@ -0,0 +1,44 @@ +Prompts +Once you have read through the above code, add a file to your Hotel project called design-activity.md. This file will be submitted with the rest of this exercise. In that file, please respond to the following prompts: + +What classes does each implementation include? Are the lists the same? + The two implementations have the same classes; CartEntry, ShoppingCart and Order. The methods within are different. + +Write down a sentence to describe each class. + CartEntry contains data on each item and its price. + ShoppingCart class contains an array of all items. + Order gives the total for all items in the Shopping card calculated with sales tax. + +How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper. + CartEntry seems to be independent of the two other classes. + ShoppingCart seems like it will be a collection of CartEntries. + Orders have ShoppingCarts. + +What data does each class store? How (if at all) does this differ between the two implementations? + CartEntry stores: @unit_price and @quantity + ShoppingCart stores: @entries + Order stores: @cart and SALES_TAX + +What methods does each class have? How (if at all) does this differ between the two implementations? + Implementation A: total_price + Implementation B: price, price, total_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? + Implementation A: retained in Order + Implementation B: Delated to other classes. + +Does total_price directly manipulate the instance variables of other classes? + Implementation A: Yes + Implementation B: No + +If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify? + We could use a conditional to on quantity and a discount rate or bulk price. + Both implementations seems like they are of similar amounts of work to modify. + +Which implementation better adheres to the single responsibility principle? + Implementation B follows the single responsibility principle more than A. + +Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? + Implementation B is more loosely coupled. +Once you've responded to the prompts, git add design-activity.md and git commit!