diff --git a/Guardfile b/Guardfile new file mode 100644 index 000000000..fa59fc3ef --- /dev/null +++ b/Guardfile @@ -0,0 +1,6 @@ +guard :minitest, bundler: false, autorun: false, rubygems: false do + # with Minitest::Spec + watch(%r{^spec/(.*)_spec\.rb$}) + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + watch(%r{^spec/spec_helper\.rb$}) { 'spec' } +end diff --git a/README.md b/README.md index 6d835497d..8e297faaf 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Reinforce and practice all of the Ruby and programming concepts we've covered in This is a [stage 3](https://github.com/Ada-Developers-Academy/pedagogy/blob/master/rule-of-three.md), individual project. +This project is due before class on **Monday September 10th** ## Introduction diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..a2f13e5cb --- /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/design-activity.md b/design-activity.md new file mode 100644 index 000000000..3bc82bedc --- /dev/null +++ b/design-activity.md @@ -0,0 +1,38 @@ +1. What classes does each implementation include? Are the lists the same? +implementation a: CartEntry, ShoppingCart, Order. +implementation b: CartEntry, ShoppingCart,Order. +Yes, the lists are the same. + +2. Write down a sentence to describe each class. +implementation a: + CartEntry- initialize cart with unit_price and quantity as local variables. + ShoppingCart- initialize cart with entries as local variable containing an empty array. + Order- define SALES_TAX, initialize order with a new instance of @cart, method for calculating the prices + by iterating through @cart entries, calling unit_price on the entry, and returning the total including sales tax. +implementation b: + CartEntry- initialize cart with unit_price and quantity as local variables, + and a method for calling price. + ShoppingCart- initialize cart as a local variable containing an empty array. + Order- define SALES_TAX, define subtotal by calling price on @cart, and returning the total including sales tax. + +3. How do the classes relate to each other? + + +4. What data does each class store? How (if at all) does this differ between the two implementations? + + + +5. What methods does each class have? How (if at all) does this differ between the two implementations? + + +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? +Does total_price directly manipulate the instance variables of other classes? + + +7. If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify? + +8. Which implementation better adheres to the single responsibility principle? + + +** Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? implementation a diff --git a/lib/.keep b/lib/.keep index e69de29bb..a8ce323e9 100644 --- a/lib/.keep +++ b/lib/.keep @@ -0,0 +1,10 @@ +User Stories +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/date_range.rb b/lib/date_range.rb new file mode 100644 index 000000000..29b54542d --- /dev/null +++ b/lib/date_range.rb @@ -0,0 +1,35 @@ +class DateRange + attr_reader :start_date, :end_date + +# def res_start(start_time = '11:00'.strftime('%k%M')) +# @res_start = res_start +# end +# def res_end(end_time = '15:00'.strftime('%k%M')) +# @res_end = res_end +# end + + # def start_date + # @start_date = DateTime.new + # end + # + # def end_date + # @end_date = DateTime.new + # end + + def initialize(start_date, end_date) + unless end_date > start_date + raise ArgumentError.new("Your dates are incorrect)") + end + @start_date = start_date.DateTime.new + @end_date = end_date.DateTime.new + end + + def contains(date) + return date >= @start_date && date < @end_date + end + + def nights + return @end_date - @start_date + end + +end diff --git a/lib/hotel_admin.rb b/lib/hotel_admin.rb new file mode 100644 index 000000000..c85f220c9 --- /dev/null +++ b/lib/hotel_admin.rb @@ -0,0 +1,70 @@ +<<<<<<< HEAD +# require_relative 'room.rb' +# require_relative 'reservation.rb' +# +# +# module Hotel +# class Admin +# attr_accessor :rooms +# def initialize +# @rooms = Hotel::Room.create_rooms +# end +# +# +# def new_reservation(room_number, start_date_time, end_date_time, cost) +# @room_number = room_number +# @start_date_time = start_date_time +# @end_date_time = end_date_time +# @cost = cost +# end +# @new_reservation +# +# def check_room_status +# @booked_rooms = [] +# @open_rooms = [] +# @rooms.each do |number, status| +# if :room_status == :Available +# status = :Unavailable +# @booked_rooms << room +# elsif :room_status == :Available +# @open_rooms << room +# end +# @booked_rooms +# @open_rooms +# end +# end +# end +# +# end +# end +======= +require_relative 'room.rb' +# require_relative 'reservation.rb' +# require_relative 'hotel_admin.rb' + +module Hotel + class Admin + attr_accessor :rooms + def initialize + @rooms = Hotel::Room.create_rooms + end + + def self.check_room_status + @booked_rooms = [] + @open_rooms = [] + @rooms.each do |number, status| + if :room_status == :Available + status = :Unavailable + @booked_rooms << room + elsif :room_status == :Available + @open_rooms << room + end + @booked_rooms + @open_rooms + end + end + end + + +end +>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b diff --git a/lib/reservation.rb b/lib/reservation.rb new file mode 100644 index 000000000..1288aeec5 --- /dev/null +++ b/lib/reservation.rb @@ -0,0 +1,104 @@ +# create module for reservations to hold classes +require 'pry' +<<<<<<< HEAD +require_relative 'date_range' +module Hotel + + class ReserveRoom < DateRange + attr_reader :room_number + attr_accessor :cost + + def initialize(start_date,end_date, cost) +======= +require_relative 'hotel_admin.rb' +module Reservation + + class ReserveRoom + attr_accessor :room_status, :start_date, :end_date, :cost, :res_id + + def initialize( start_date_time, end_date_time, res_id, cost = 200) + @start_date = DateTime.strptime(start_date_time + " 15:00", "%m/%d/%y %H:%M") + @end_date = DateTime.strptime(end_date_time + " 11:00", "%m/%d/%y %H:%M") + @res_id = res_id +>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b + @cost = cost + super(start_date, end_date) + end + +<<<<<<< HEAD + def self.create_reservation + end + + def calculate_cost + nights = @end_date - @start_date + @cost = nights * 200.to_f + end + + def available_rooms + dates = DateRange.new(start_date, end_date) + available_rooms = @rooms + end +======= + # def self.create_reservation + # end + + def calculate_cost + num_nights = (end_date - start_date).to_i + @room_cost = (num_nights + 1) * 200.to_f + end + + # def check_room_status + # @rooms.each do |status| + # if :room_status == :Available + # puts 'Room is Available.' + # elsif :room_status == :Unavailable + # puts 'Room is Unavailable.' + # end + # end + # end +>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b + end +end + +# def check_room_status +# @rooms.each do |status| +# if :room_status == :Available +# puts 'Room is Available.' +# elsif :room_status == :Unavailable +# puts 'Room is Unavailable.' +# end +# end +# end +# end +# end +# +# +# open_rooms = [] +# reserved_rooms = [] +# def lists_booked_rooms +# start_date = Date.parse('20/09/2018') +# end_date = Date.parse ('30/09/2018') +# date_range = (start_date..end_date) +# @all_rooms.to_a.each do |room| +# @booked_rooms.to_a.each do |room| +# if all_rooms.room_number != booked_rooms.room_number +# open_rooms << room +# elsif all_rooms.room_number == booked_rooms.room_number +# reserved_rooms << room +# end +# end +# end +# end + +# Two date ranges *do* overlap if range A compared to range B: +# - Same dates +# - Overlaps in the front +# - Overlaps in the back +# - Completely contained +# - Completely containing +# +# Two date ranges are *not* overlapping if range A compared to range B: +# - Completely before +# - Completely after +# - Ends on the checkin date +# - Starts on the checkout date diff --git a/lib/room.rb b/lib/room.rb new file mode 100644 index 000000000..1ef951a54 --- /dev/null +++ b/lib/room.rb @@ -0,0 +1,51 @@ +require_relative 'reservation' + +module Hotel + class Room + attr_reader :room_number + attr_accessor :status + + def initialize(room_number, status = :Available) + @room_number = room_number + @status = status + end + def self.create_rooms + @all_rooms = [ ] + room_number = 0 + 20.times do + room_number += 1 + @all_rooms << Room.new(room_number) + end + return @all_rooms + end + def self.list_all_rooms + @all_rooms = self.create_rooms + return @all_rooms + end + end +end +# module Hotel +# # create new class of Room, to create the block of rooms +# class Room +# attr_accessor :rooms, :room_cost, :reservations +# +# +# def initialize +# @rooms = rooms +# @room_cost = 200 +# @reservations = [] +# @blocks = [] +# end +# +# def create_rooms +# 20.times do +# @all_rooms << Room.new +# end +# puts @all_rooms +# end +# +# def room_list +# return @all_rooms +# end +# end +# end diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb new file mode 100644 index 000000000..70b21b760 --- /dev/null +++ b/specs/date_range_spec.rb @@ -0,0 +1,10 @@ +require_relative 'spec_helper' + +describe 'DateRange Class' do + describe 'initialize date_range' do + it 'is an instance of date_range' do + test_date_range = DateRange.new('09/20/18', '09/22/18') + expect(test_date_range).must_be_kind_of DateRange + end + end +end diff --git a/specs/hotel_admin_spec.rb b/specs/hotel_admin_spec.rb new file mode 100644 index 000000000..926b4f065 --- /dev/null +++ b/specs/hotel_admin_spec.rb @@ -0,0 +1,49 @@ +require_relative 'spec_helper' +<<<<<<< HEAD +# require_relative '../lib/hotel_admin.rb' +======= +require_relative '../lib/hotel_admin.rb' +>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b + + +describe 'Admin Class' do + describe 'initialize Admin' do + it 'it is an instance of Admin' do + @test_admin = Hotel::Admin.new + expect(@test_admin).must_be_kind_of Hotel::Admin + end + end + +<<<<<<< HEAD +it 'reserves a room for a specific date' do + @new_reservation = Hotel::New_Reservation.new_reservation.new + expect(@new_reservation).must_be_kind_of Hotel::Reservation +end + +======= +>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b + it 'creates a list of twenty rooms' do + @rooms = Hotel::Room.create_rooms + expect(@rooms.length).must_equal 20 + end + +<<<<<<< HEAD + it 'can check the status of a room' do + @test_room = Hotel::Admin.new + expect(@test_room.check_room_status).must_equal Unavailable + end + it 'creates a reservation' do + test_reservation = Hotel::Admin.create_reservation.new( '09/20/18', '09/22/18', 1) + expect(test_reservation).must_be_kind_of Reservation::ReserveRoom + end +======= + # it 'can check the status of a room' do + # @test_room = Hotel::Admin.new + # expect(@test_room.check_room_status).must_equal Unavailable + # end + # it 'creates a reservation' do + # test_reservation = Hotel::Admin.create_reservation.new( '09/20/18', '09/22/18', 1) + # expect(test_reservation).must_be_kind_of Reservation::ReserveRoom + # end +>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b +end diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb new file mode 100644 index 000000000..2767920ef --- /dev/null +++ b/specs/reservation_spec.rb @@ -0,0 +1,43 @@ +require_relative 'spec_helper' + + +describe 'Reservation Class' do + describe 'initialize a reservation' do + it 'creates an instance of a reservation' do +<<<<<<< HEAD + test_reservation = Hotel::ReserveRoom.new +======= + test_reservation = Reservation::ReserveRoom.new( '09/20/18', '09/22/18', 1) +>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b + expect(test_reservation).must_be_kind_of Reservation::ReserveRoom + end + it 'can check the status of a new room' do + @room = Hotel::Room.new(1) + expect(@room.status).must_equal :Available + end + + it 'can calculate the cost of a reservation' do +<<<<<<< HEAD + @test_reservation = Hotel::ReserveRoom.new('09/20/18', '09/22/18') +======= + @test_reservation = Reservation::ReserveRoom.new( '09/20/18', '09/22/18', 12) + +>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b + expect(@test_reservation.calculate_cost).must_equal 400.0 + end + end + +<<<<<<< HEAD + it 'can check the status of a room' do + @test_room = Reservation::ReserveRoom.new( '09/20/18', '09/22/18', 1, 200) + + expect(@test_room.check_room_status).must_equal Unavailable + end +======= + # it 'can check the status of a room' do + # @test_room = Reservation::ReserveRoom.new( '09/20/18', '09/22/18', 1, 200) + # binding.pry + # expect(@test_room.check_room_status).must_equal Unavailable + # end +>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b +end diff --git a/specs/room_spec.rb b/specs/room_spec.rb new file mode 100644 index 000000000..e0404ff01 --- /dev/null +++ b/specs/room_spec.rb @@ -0,0 +1,28 @@ +require_relative 'spec_helper' + +describe 'Rooms Class' do + describe 'initialize rooms' do + it 'is an instance of Room' do + test_room = Hotel::Room.new(1) + expect(test_room).must_be_kind_of Hotel::Room + end + end +<<<<<<< HEAD + + it 'creates a list of twenty rooms' do + @all_rooms = Hotel::Room.create_rooms + expect(@all_rooms.length).must_equal 20 + end + +======= + it 'has a room number' do + @room = Hotel::Room.new(5) + expect(@room.room_number).must_equal 5 + end + + # it 'creates a list of twenty rooms' do + # @all_rooms = Hotel::Room.create_rooms + # expect(@all_rooms.length).must_equal 20 + # end +>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b +end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb new file mode 100644 index 000000000..a6fb42de1 --- /dev/null +++ b/specs/spec_helper.rb @@ -0,0 +1,13 @@ +require 'simplecov' +SimpleCov.start +require 'minitest' +require 'minitest/pride' +require 'minitest/autorun' +require 'minitest/reporters' + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new + +require_relative '../lib/room.rb' +require_relative '../lib/reservation.rb' +require_relative '../lib/date_range.rb' +require_relative '../lib/hotel_admin.rb'