From 141be865710c14557ab9183d19e2b9f005b2f570 Mon Sep 17 00:00:00 2001 From: Stef Date: Wed, 6 Sep 2017 14:14:31 -0700 Subject: [PATCH 1/8] Rakefile and very basic skeleton creation complete. --- Rakefile | 9 +++++++++ lib/reservations.rb | 0 specs/reservations_spec.rb | 1 + specs/spec_helper.rb | 6 ++++++ 4 files changed, 16 insertions(+) create mode 100644 Rakefile create mode 100644 lib/reservations.rb create mode 100644 specs/reservations_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/reservations.rb b/lib/reservations.rb new file mode 100644 index 000000000..e69de29bb diff --git a/specs/reservations_spec.rb b/specs/reservations_spec.rb new file mode 100644 index 000000000..ae9c220ea --- /dev/null +++ b/specs/reservations_spec.rb @@ -0,0 +1 @@ +require_relative 'spec_helper' diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb new file mode 100644 index 000000000..d39672ce9 --- /dev/null +++ b/specs/spec_helper.rb @@ -0,0 +1,6 @@ +require 'simplecov' +SimpleCov.start +require 'minitest/autorun' +require 'minitest/reporters' +require 'minitest/skip_dsl' +require_relative '../lib/reservations' From 07b03ce3b579fba2cf8c155cca98cf6d822e85ed Mon Sep 17 00:00:00 2001 From: Stef Date: Sat, 9 Sep 2017 10:30:26 -0700 Subject: [PATCH 2/8] Base skeleton build complete, work start on reservations and test. --- .DS_Store | Bin 0 -> 6148 bytes lib/hotel.rb | 0 lib/reservations.rb | 20 ++++++++++++++++++++ lib/rooms.rb | 12 ++++++++++++ specs/hotel_spec.rb | 21 +++++++++++++++++++++ specs/reservations_spec.rb | 20 ++++++++++++++++++++ specs/rooms_spec.rb | 21 +++++++++++++++++++++ 7 files changed, 94 insertions(+) create mode 100644 .DS_Store create mode 100644 lib/hotel.rb create mode 100644 lib/rooms.rb create mode 100644 specs/hotel_spec.rb create mode 100644 specs/rooms_spec.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..10f4d43063cf2afdea345ed0e8725c067b6d3ef7 GIT binary patch literal 6148 zcmeH~O=`nH427SXECStlndNM9fZkvT$q90S5(*^{5-7CmIeMRdHg&o#raXc4Mj8v- z-@;=7u>I%T3orrL&|R_fFf(Jm!W9>szfK>w>;3l5idTWBh?%i6VYXk}5)lvq5fA|p z5P<~|$Wt7f=LJ2J9z_I1U>OAb`_SmFy>z6;r-LCz0P33MFs@^kpf)d1d+A7Jg=RH9 zShZS=AzqJmYOCvd=}66XSPdUmcQ&75XqN4;#)M`)L_q{ZU`Ak-`Q+#Sk^bBKKWkAc z0wVCw2-x~?I_&vUb+$gdp4VTi>gz$L#^nq@egc^IQM{#xaliS3+Dk_&D>VHG1O^2W H_)`MkvH%f) literal 0 HcmV?d00001 diff --git a/lib/hotel.rb b/lib/hotel.rb new file mode 100644 index 000000000..e69de29bb diff --git a/lib/reservations.rb b/lib/reservations.rb index e69de29bb..afdf4e96d 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -0,0 +1,20 @@ +require_relative 'rooms' +require_relative 'hotel' + +module HotelHedwig + class Reservations + attr_reader :rooms + def initialize + + end + end +end + +# Start pseudocode to build + +# User Stories Wave 1; + +# As an administrator, I can access the list of all of the rooms in the hotel +# As an administrator, I can reserve a room for a given date range +# As an administrator, I can access the list of reservations for a specific date +# As an administrator, I can get the total cost for a given reservation diff --git a/lib/rooms.rb b/lib/rooms.rb new file mode 100644 index 000000000..0b431be5a --- /dev/null +++ b/lib/rooms.rb @@ -0,0 +1,12 @@ +# What do I want this to do? +# I want this to be a place holder for the rooms in an array. +# There are 20 rooms, numbered 1 - 20 + +module HotelHedwig + class Rooms + attr_reader + def initialize + + end + end +end diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb new file mode 100644 index 000000000..966651be1 --- /dev/null +++ b/specs/hotel_spec.rb @@ -0,0 +1,21 @@ +require_relative 'spec_helper' + +describe "Hotel" do + describe "#initialize" do + it "must " do + HotelHedwig::Hotel.new() + end + end +end + +# Test pseudoode + +describe "" do + it "" do + end + end + + describe "" do + it "" do + end + end diff --git a/specs/reservations_spec.rb b/specs/reservations_spec.rb index ae9c220ea..897ec0693 100644 --- a/specs/reservations_spec.rb +++ b/specs/reservations_spec.rb @@ -1 +1,21 @@ require_relative 'spec_helper' + +describe "Reservations" do + describe "#initialize" do + it "must " do + HotelHedwig::Reservations.new() + end + end +end + +# Test pseudocode + +describe "" do + it "" do + end + end + + describe "" do + it "" do + end + end diff --git a/specs/rooms_spec.rb b/specs/rooms_spec.rb new file mode 100644 index 000000000..6dc8d7266 --- /dev/null +++ b/specs/rooms_spec.rb @@ -0,0 +1,21 @@ +require_relative 'spec_helper' + +describe "Rooms" do + describe "#initialize" do + it "must " do + HotelHedwig::Rooms.new() + end + end +end + +# Test pseudoode + +describe "" do + it "" do + end + end + + describe "" do + it "" do + end + end From 9ef7608b27883ac7badcede8ea5c9b6091d6ccb0 Mon Sep 17 00:00:00 2001 From: Stef Date: Sun, 10 Sep 2017 15:13:28 -0700 Subject: [PATCH 3/8] Pseudocode start, room lib looking okay. --- lib/hotel.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/reservations.rb | 19 +++++++++---------- lib/rooms.rb | 16 ++++++++++------ 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index e69de29bb..7c944182d 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -0,0 +1,43 @@ +# All buisiness logic here (changed mind from reservations) + +require_relative 'rooms' +require_relative 'hotel' + +module HotelHedwig + class Reservations + attr_reader :rooms + def initialize + + end +# Start pseudocode to build Wave 1 + def method to access all of the rooms + + end + + def method to reserve a room in a date range. + + end + + def method to access list of reservations for a specific date. + + end + + def method to get total cost for a given reservation. + + end + end +end + +# User Stories Wave 1; + +# As an administrator, I can access the list of all of the rooms in the hotel +# As an administrator, I can reserve a room for a given date range +# As an administrator, I can access the list of reservations for a specific date +# As an administrator, I can get the total cost for a given reservation + +# Constraints + +# The hotel has 20 rooms, and they are numbered 1 through 20 +# Every room is identical, and a room always costs $200/night +# The last day of a reservation is the checkout day, so the guest should not be charged for that night +# For this wave, any room can be reserved at any time, and you don't need to check whether reservations conflict with each other (this will come in wave 2!) diff --git a/lib/reservations.rb b/lib/reservations.rb index afdf4e96d..ea4bfee1d 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -1,5 +1,4 @@ -require_relative 'rooms' -require_relative 'hotel' +# All reservation logic here, keep it simple. module HotelHedwig class Reservations @@ -7,14 +6,14 @@ class Reservations def initialize end - end -end -# Start pseudocode to build + def method for date range (365 days in a year) + + end + + def method for available/unavailable dates -# User Stories Wave 1; + end -# As an administrator, I can access the list of all of the rooms in the hotel -# As an administrator, I can reserve a room for a given date range -# As an administrator, I can access the list of reservations for a specific date -# As an administrator, I can get the total cost for a given reservation + end +end diff --git a/lib/rooms.rb b/lib/rooms.rb index 0b431be5a..c5bad7e65 100644 --- a/lib/rooms.rb +++ b/lib/rooms.rb @@ -1,12 +1,16 @@ -# What do I want this to do? -# I want this to be a place holder for the rooms in an array. -# There are 20 rooms, numbered 1 - 20 +# Room logic. +# 20 rooms numbered 1 - 20. +# Each room is $200 + module HotelHedwig class Rooms - attr_reader - def initialize - + + attr_reader :room_num, :room_cost + + def initialize(room_num) + @room_num = room_num + @room_cost = 200 end end end From 161979cdfb4ba7ae82f5b3d096e2abdc9db443bd Mon Sep 17 00:00:00 2001 From: Stef Date: Sun, 10 Sep 2017 18:16:09 -0700 Subject: [PATCH 4/8] Rake issues, start over. --- lib/hotel.rb | 61 +++++++++++++++++++------------------- lib/reservations.rb | 38 ++++++++++++------------ lib/rooms.rb | 3 +- specs/hotel_spec.rb | 42 +++++++++++++------------- specs/reservations_spec.rb | 42 +++++++++++++------------- specs/rooms_spec.rb | 20 ++++++------- specs/spec_helper.rb | 2 ++ 7 files changed, 104 insertions(+), 104 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 7c944182d..ecfbe4ba7 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,34 +1,35 @@ # All buisiness logic here (changed mind from reservations) - -require_relative 'rooms' -require_relative 'hotel' - -module HotelHedwig - class Reservations - attr_reader :rooms - def initialize - - end -# Start pseudocode to build Wave 1 - def method to access all of the rooms - - end - - def method to reserve a room in a date range. - - end - - def method to access list of reservations for a specific date. - - end - - def method to get total cost for a given reservation. - - end - end -end - -# User Stories Wave 1; +# +# require_relative 'rooms' +# require_relative 'hotel' +# +# module HotelHedwig +# class Reservations +# attr_reader :rooms +# def initialize +# +# end + +# # Start pseudocode +# def method to access all of the rooms +# +# end +# +# def method to reserve a room in a date range. +# +# end +# +# def method to access list of reservations for a specific date. +# +# end +# +# def method to get total cost for a given reservation. +# +# end +# end +# end + +# User Stories Wave 1 (methods); # As an administrator, I can access the list of all of the rooms in the hotel # As an administrator, I can reserve a room for a given date range diff --git a/lib/reservations.rb b/lib/reservations.rb index ea4bfee1d..2b17ee696 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -1,19 +1,19 @@ -# All reservation logic here, keep it simple. - -module HotelHedwig - class Reservations - attr_reader :rooms - def initialize - - end - - def method for date range (365 days in a year) - - end - - def method for available/unavailable dates - - end - - end -end +# # All reservation logic here, keep it simple. +# +# module HotelHedwig +# class Reservations +# attr_reader +# def initialize +# +# end +# +# def method for date range (365 days in a year) +# +# end +# +# def method for available/unavailable dates +# +# end +# +# end +# end diff --git a/lib/rooms.rb b/lib/rooms.rb index c5bad7e65..12d1bfc36 100644 --- a/lib/rooms.rb +++ b/lib/rooms.rb @@ -2,12 +2,11 @@ # 20 rooms numbered 1 - 20. # Each room is $200 - module HotelHedwig class Rooms attr_reader :room_num, :room_cost - + def initialize(room_num) @room_num = room_num @room_cost = 200 diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 966651be1..d695dc7d5 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -1,21 +1,21 @@ -require_relative 'spec_helper' - -describe "Hotel" do - describe "#initialize" do - it "must " do - HotelHedwig::Hotel.new() - end - end -end - -# Test pseudoode - -describe "" do - it "" do - end - end - - describe "" do - it "" do - end - end +# require_relative 'spec_helper' +# +# describe "Hotel" do +# describe "#initialize" do +# it "must " do +# HotelHedwig::Hotel.new() +# end +# end +# end +# +# # Test pseudoode +# +# describe "" do +# it "" do +# end +# end +# +# describe "" do +# it "" do +# end +# end diff --git a/specs/reservations_spec.rb b/specs/reservations_spec.rb index 897ec0693..053b502cc 100644 --- a/specs/reservations_spec.rb +++ b/specs/reservations_spec.rb @@ -1,21 +1,21 @@ -require_relative 'spec_helper' - -describe "Reservations" do - describe "#initialize" do - it "must " do - HotelHedwig::Reservations.new() - end - end -end - -# Test pseudocode - -describe "" do - it "" do - end - end - - describe "" do - it "" do - end - end +# require_relative 'spec_helper' +# +# describe "Reservations" do +# describe "#initialize" do +# it "must " do +# HotelHedwig::Reservations.new() +# end +# end +# end +# +# # Test pseudocode +# +# describe "" do +# it "" do +# end +# end +# +# describe "" do +# it "" do +# end +# end diff --git a/specs/rooms_spec.rb b/specs/rooms_spec.rb index 6dc8d7266..c7720e7a0 100644 --- a/specs/rooms_spec.rb +++ b/specs/rooms_spec.rb @@ -2,20 +2,18 @@ describe "Rooms" do describe "#initialize" do - it "must " do - HotelHedwig::Rooms.new() + before do + @room_1 = HotelHedwig::Rooms.new(1) end + it "Can instantiate" + @room_1.must_be_kind_of HotelHedwig::Rooms.new end -end - -# Test pseudoode -describe "" do - it "" do - end + it "Can access a room number." do + @room_1.room_num.must_equal 1 end - describe "" do - it "" do - end + it "Can access the cost of a room per night." do + @room_1.room_cost.must_equal 200 end +end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index d39672ce9..62e43c833 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -3,4 +3,6 @@ require 'minitest/autorun' require 'minitest/reporters' require 'minitest/skip_dsl' +require_relative '../lib/rooms' +require_relative '../lib/hotel' require_relative '../lib/reservations' From f9d5af268057270acd486b6985eb5d5531b9a766 Mon Sep 17 00:00:00 2001 From: Stef Date: Sun, 10 Sep 2017 21:59:06 -0700 Subject: [PATCH 5/8] Rooms and Reservation classes fleshed out, base set for Hotel. --- lib/hotel.rb | 18 +++++++++++---- lib/reservations.rb | 53 +++++++++++++++++++++++++++++---------------- lib/rooms.rb | 23 +++++++++++++++----- specs/rooms_spec.rb | 17 ++++++++------- 4 files changed, 75 insertions(+), 36 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index ecfbe4ba7..bf48209c2 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,16 +1,26 @@ -# All buisiness logic here (changed mind from reservations) -# +# All buisiness logic here (changed mind from reservations because this makes most sense). + +# I need for this to access all of the rooms in the room class. + +# I need for this to access all of the reservations, the reservations class holds my dates for the reservations. + +# I need for this to provide a total charge amount for the days reserved. + +# Somehow I need this to provide reservation list that is DATE specific. This will be tricky (IMO). + # require_relative 'rooms' -# require_relative 'hotel' +# require_relative 'reservations' # # module HotelHedwig # class Reservations -# attr_reader :rooms +# attr_reader # def initialize # # end # # Start pseudocode +# Remember to not duplicate methods! + # def method to access all of the rooms # # end diff --git a/lib/reservations.rb b/lib/reservations.rb index 2b17ee696..2753662d8 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -1,19 +1,34 @@ -# # All reservation logic here, keep it simple. -# -# module HotelHedwig -# class Reservations -# attr_reader -# def initialize -# -# end -# -# def method for date range (365 days in a year) -# -# end -# -# def method for available/unavailable dates -# -# end -# -# end -# end +# Logic for reservations here, aka reservation dates. +# I need this to require the date gem. +# This must initialize check in and check out dates +# This must also take those dates and use a method to calculate charges. +# I need to make sure that I can access this information in the hotel class which is going to hold all of the biz logic. + +require 'date' +require 'rooms' + +module HotelHedwig + class Reservations + + attr_reader :check_in, :check_out + + def initialize(check_in, check_out) + @check_in = check_in + @check_out = check_out + + # Raise an argument error IF the check-in date is after the check-out date! + + # Argument error conditional? How to do this 'before'. + # Pseudocode; + # if @check_in before @check_out + # raise ArgumentError "Invalid date selection, please check and change your check-in and check-out dates." + # end + + # Calculating costs take 3, not sure how to best calculate this or if it belongs here. The idea is using the base amount aka room_cost (200) multiplied by the number of days customer stays. Check out day minus check in day provides that number. I hope. This should also allow for a one day stay ex. 200 * (day 2 - day 1) = 200 * 1 = 200. + + def charges + @room_rate = room_rate * (@check_out - @check_in).to_i + end + end + end +end diff --git a/lib/rooms.rb b/lib/rooms.rb index 12d1bfc36..03a6bdc39 100644 --- a/lib/rooms.rb +++ b/lib/rooms.rb @@ -1,15 +1,28 @@ -# Room logic. -# 20 rooms numbered 1 - 20. -# Each room is $200 +# Room logic. SIMPLE +# I need this to provide me with 20 numbered rooms starting at the number 1 and ending at the number 20. +# This also needs to (I believe) hold the room cost. Each room has a $200 charge per night. module HotelHedwig class Rooms - attr_reader :room_num, :room_cost + attr_reader :room_num, :room_rate + +# Initialize variables to access the room number AND the charge per room. I believe this will make it easier to calculate in the end. def initialize(room_num) @room_num = room_num - @room_cost = 200 + @room_rate = 200 + end + +# Using a self.all method to work out the room numbering system. + + def self.all + rooms = [] + room_num = 0 + 20.times do + number += 1 + rooms << self.new(room_num) + end end end end diff --git a/specs/rooms_spec.rb b/specs/rooms_spec.rb index c7720e7a0..8b88fe175 100644 --- a/specs/rooms_spec.rb +++ b/specs/rooms_spec.rb @@ -5,15 +5,16 @@ before do @room_1 = HotelHedwig::Rooms.new(1) end - it "Can instantiate" - @room_1.must_be_kind_of HotelHedwig::Rooms.new - end - it "Can access a room number." do - @room_1.room_num.must_equal 1 - end +# Basic needs tests to access room numbers and the cost. +# Can I do anything else? - it "Can access the cost of a room per night." do - @room_1.room_cost.must_equal 200 + it "Can access a room number." do + @room_1.room_num.must_equal 1 + end + + it "Can access the cost of a room per night." do + @room_1.room_cost.must_equal 200 + end end end From 0afe16ad6eca431f2409886f993c9eea84562866 Mon Sep 17 00:00:00 2001 From: Stef Date: Mon, 11 Sep 2017 00:37:57 -0700 Subject: [PATCH 6/8] Rooms and Reservation classes and tests working, though weird warning about previous definition line 21, unsure... --- lib/reservations.rb | 16 +++++---------- specs/reservations_spec.rb | 41 +++++++++++++++++++------------------- specs/rooms_spec.rb | 14 ++++++++++--- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 2753662d8..01bb77bf9 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -16,18 +16,12 @@ def initialize(check_in, check_out) @check_in = check_in @check_out = check_out - # Raise an argument error IF the check-in date is after the check-out date! + # Raise an argument error IF the check-in date is after the check-out date! Method? - # Argument error conditional? How to do this 'before'. - # Pseudocode; - # if @check_in before @check_out - # raise ArgumentError "Invalid date selection, please check and change your check-in and check-out dates." - # end - - # Calculating costs take 3, not sure how to best calculate this or if it belongs here. The idea is using the base amount aka room_cost (200) multiplied by the number of days customer stays. Check out day minus check in day provides that number. I hope. This should also allow for a one day stay ex. 200 * (day 2 - day 1) = 200 * 1 = 200. - - def charges - @room_rate = room_rate * (@check_out - @check_in).to_i + def invalid_date + if @check_in < @check_out + raise ArgumentError.new "Invalid date selection, please check and change your check-in and check-out dates." + end end end end diff --git a/specs/reservations_spec.rb b/specs/reservations_spec.rb index 053b502cc..b05d8cbe3 100644 --- a/specs/reservations_spec.rb +++ b/specs/reservations_spec.rb @@ -1,21 +1,20 @@ -# require_relative 'spec_helper' -# -# describe "Reservations" do -# describe "#initialize" do -# it "must " do -# HotelHedwig::Reservations.new() -# end -# end -# end -# -# # Test pseudocode -# -# describe "" do -# it "" do -# end -# end -# -# describe "" do -# it "" do -# end -# end +require_relative 'spec_helper' + +describe "Reservations" do + before do + @check_in = Date.new(2017,9,11) + @check_out = Date.new(2017,9,13) + @reservation_dates = HotelHedwig::Reservations.new(@check_in, @check_out) + # @charges = 200 * (@check_out - @check_in) + end + + it "Must be instance of Reservations" do + @reservation_dates.must_be_instance_of HotelHedwig::Reservations + end + + describe "invalid_date" do + it "must raise argument error if check in date is after check out date" do + proc { HotelHedwig::Reservations.new(@check_in > @check_out) }.must_raise ArgumentError + end + end +end diff --git a/specs/rooms_spec.rb b/specs/rooms_spec.rb index 8b88fe175..3a87f9251 100644 --- a/specs/rooms_spec.rb +++ b/specs/rooms_spec.rb @@ -6,15 +6,23 @@ @room_1 = HotelHedwig::Rooms.new(1) end -# Basic needs tests to access room numbers and the cost. -# Can I do anything else? + # Basic needs tests to access room numbers and the cost. + # Can I do anything else? it "Can access a room number." do @room_1.room_num.must_equal 1 end it "Can access the cost of a room per night." do - @room_1.room_cost.must_equal 200 + @room_1.room_rate.must_equal 200 + end + + it "Must respond to room_num" do + @room_1.must_respond_to :room_num + end + + it "Must be instance of HotelHedwig module and Rooms class" do + @room_1.must_be_instance_of HotelHedwig::Rooms end end end From 8f7f1a644eb4b4da95ac033b5a02d7c92e2d3000 Mon Sep 17 00:00:00 2001 From: Stef Date: Mon, 11 Sep 2017 01:01:41 -0700 Subject: [PATCH 7/8] Hotel class pseudocode, can't find initial work, doing over. Warning still there for reservations, frustrating. --- lib/hotel.rb | 68 +++++++++++++++++++++----------------- lib/reservations.rb | 4 ++- specs/hotel_spec.rb | 59 +++++++++++++++++++++------------ specs/reservations_spec.rb | 7 ++-- 4 files changed, 82 insertions(+), 56 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index bf48209c2..a61af4e11 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -8,36 +8,43 @@ # Somehow I need this to provide reservation list that is DATE specific. This will be tricky (IMO). -# require_relative 'rooms' -# require_relative 'reservations' -# -# module HotelHedwig -# class Reservations -# attr_reader -# def initialize -# -# end - -# # Start pseudocode -# Remember to not duplicate methods! - -# def method to access all of the rooms -# -# end -# -# def method to reserve a room in a date range. -# -# end -# -# def method to access list of reservations for a specific date. -# -# end -# -# def method to get total cost for a given reservation. -# -# end -# end -# end +require_relative 'rooms' +require_relative 'reservations' + +module HotelHedwig + class Reservations + attr_reader :rooms, :check_in, :check_out, :total_charges + def initialize(rooms, check_in, check_out, total_charges) + @rooms = rooms + @check_in = check_in + @check_out = check_out + @total_charges = total_charges + end + + # Start pseudocode + # Remember to not duplicate methods! + + def all_rooms + @rooms = [] + end + + def reserve_room(room, check_in, check_out) + + + end + + def date_reservations + + end + + # Calculating costs take 3, not sure how to best calculate this or if it belongs here. The idea is using the base amount aka room_cost (200) multiplied by the number of days customer stays. Check out day minus check in day provides that number. I hope. This should also allow for a one day stay ex. 200 * (day 2 - day 1) = 200 * 1 = 200. + + def total_charges + @room_rate = room_rate * (@check_out - @check_in).to_i + end + end +end + # User Stories Wave 1 (methods); @@ -51,4 +58,3 @@ # The hotel has 20 rooms, and they are numbered 1 through 20 # Every room is identical, and a room always costs $200/night # The last day of a reservation is the checkout day, so the guest should not be charged for that night -# For this wave, any room can be reserved at any time, and you don't need to check whether reservations conflict with each other (this will come in wave 2!) diff --git a/lib/reservations.rb b/lib/reservations.rb index 01bb77bf9..9e36bfd28 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -18,9 +18,11 @@ def initialize(check_in, check_out) # Raise an argument error IF the check-in date is after the check-out date! Method? + # Why is invalid_date raising a warning??? + def invalid_date if @check_in < @check_out - raise ArgumentError.new "Invalid date selection, please check and change your check-in and check-out dates." + raise ArgumentError.new("Invalid date selection, please check and change your check-in and check-out dates.") end end end diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index d695dc7d5..189e79b94 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -1,21 +1,38 @@ -# require_relative 'spec_helper' -# -# describe "Hotel" do -# describe "#initialize" do -# it "must " do -# HotelHedwig::Hotel.new() -# end -# end -# end -# -# # Test pseudoode -# -# describe "" do -# it "" do -# end -# end -# -# describe "" do -# it "" do -# end -# end +require_relative 'spec_helper' + +describe "Hotel" do + before do + @check_in = Date.new(2017,9,11) + @check_out = Date.new(2017,9,13) + @reservation_dates = HotelHedwig::Reservations.new(@check_in, @check_out) + end + + + # Test pseudocode + + describe "#initialize" do + it "" do + end + end + + describe "all_rooms" do + it "Must be an array of rooms" do + end + end + + describe "reserve_room" do + it "Must allow reservation by date range" do + end + end + + describe "date_reservations" do + it "Must be able to access reservation list by specific date" do + end + end + + describe "total_charges" do + it "Must have a charge of $200 per night" do + @charges.must_equal + end + end +end diff --git a/specs/reservations_spec.rb b/specs/reservations_spec.rb index b05d8cbe3..84c2ab7f2 100644 --- a/specs/reservations_spec.rb +++ b/specs/reservations_spec.rb @@ -5,7 +5,6 @@ @check_in = Date.new(2017,9,11) @check_out = Date.new(2017,9,13) @reservation_dates = HotelHedwig::Reservations.new(@check_in, @check_out) - # @charges = 200 * (@check_out - @check_in) end it "Must be instance of Reservations" do @@ -13,8 +12,10 @@ end describe "invalid_date" do - it "must raise argument error if check in date is after check out date" do - proc { HotelHedwig::Reservations.new(@check_in > @check_out) }.must_raise ArgumentError + it "Must raise argument error if check-in date is after check out date" do + proc { HotelHedwig::Reservations.new(@check_in < @check_out) }.must_raise ArgumentError end end end + +# More testing needed. Big time. From 9185fca7ce8a60a20d2cdf6c58a9db4bfb1e6ac8 Mon Sep 17 00:00:00 2001 From: Stef Date: Tue, 10 Oct 2017 02:18:06 -0700 Subject: [PATCH 8/8] Design Activity complete. --- design-activity.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 design-activity.md diff --git a/design-activity.md b/design-activity.md new file mode 100644 index 000000000..e02d11e7c --- /dev/null +++ b/design-activity.md @@ -0,0 +1,64 @@ +Prompts + +1. What classes does each implementation include? Are the lists the same? + + Implementation A - CartEntry, ShoppingCart, Order + + Implementation B - CartEntry, ShoppingCart, Order + + Yes, they look to be the same, the differences look to be in the methods. + +2. Write down a sentence to describe each class. +How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper. + + Implementation A - To calculate the price of the Order, the Order class has to access the instance variables of CartEntry and ShoppingCart in order to calculate the total_price. + + Implementation B - In this case it is the ShoppingCart class which calls the price method of CartEntry in order to calculate the price of all instances (@entries) of CartEntry. From there the Order class calls the price method from the ShoppingCart class to calculate the total of everything that is located in @cart. + + All in all Implementation B is much more sensical, especially seeing them side-by-side. + +4. What data does each class store? How (if at all) does this differ between the two implementations? + + Each class stores the same data in both implementations. + + CartEntry stores data for quantity and unit price of each instance of CartEntry in the ShoppingCart class. + + ShoppingCart contains all of these instances in an array. + + Order contains a constant variable. This is set equal to the sales tax, as well as, an instance of ShoppingCart. + +5. What methods does each class have? How (if at all) does this differ between the two implementations? + + The methods between the two implementations do differ, as such; + + Implementation A - The classes CartEntry and ShoppingCart have only initialize methods. There is one main method with all of the logic placed in the Order class. This method essentially does the order pricing calculations and does so by directly accessing/using the instance variables located in ShoppingCart and CartEntry. + + Implementation B - The classes have changed here with CartEntry and ShoppingCart now containing their own price methods with logic that allows for them to calculate the total price of the Order class. + + CartEntry's calculation method calculates the cost of an instance of CartEntry. ShoppingCart's method calculates the total cost of all instances of CartEntry via @entries, which it does by calling the price method of CartEntry from within the class of ShoppingCart. The addition of the Order class having a total_price method that adds in tax to the sum by calling on the price method in ShoppingCart. + +6. 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 - Logic is in the Order class, with the total_price method directly reading the instance variables of the ShoppingCart and CartEntry which then provides a calculation via the total_price method. + + Implementation B - There is a change in logic, which is now in the 'lower level classes'. In order to calculate total_price the 'higher level classes' call on the methods of the instances provided in the 'lower level' instead of calling on them directly as in Implementation A. + +7. Does total_price directly manipulate the instance variables of other classes? + + Implementation A - There is a small degree of manipulation with the entries through the loop. + + Implementation B - No, not in this case that I could tell. + +8. If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify? + + Implementation B - It is much easier to change the logic of the price method and provide/add a 'discount' depending on what is considered bulk. Thus defining what is considered 'bulk' and worthy of a discounted rate, then setting up that discount in the price method as a conditional could be one way to potentially go about this. + +9. Which implementation better adheres to the single responsibility principle? + + Implementation B - This because the classes in B have both behaviour and state. Adding that the methods of higher level classes don't rely directly on the lower level classes. + +10. Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? + + Implementation B - This because the classes components are in my opinion what I would call more 'self-reliant' and work more cohesively together due to that.