Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amy Lee -- Carets #31

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
681579e
Setup of project structure for Hotel project
ayjlee Sep 5, 2017
86e2d67
Created and tested initialize methods for Hotel::Room class
ayjlee Sep 5, 2017
09030e3
First draft of reserve room method and tests written, passing; placeh…
ayjlee Sep 6, 2017
75897f5
added Room.find_by_id method to find a room by it's room number
ayjlee Sep 6, 2017
b2cd5f1
tested that I could have multiple reservations on the same room
ayjlee Sep 6, 2017
9b1783a
get a list of all reservations on a certain date; wrote basic functio…
ayjlee Sep 6, 2017
531f35e
Added test for checking that each room has a nightly rate of 00
ayjlee Sep 6, 2017
3638f06
Wrote cost method that returns the total cost of a reservation, basic…
ayjlee Sep 6, 2017
100fffe
BENCHMARK: Wave 1 test requirements with basic test passing. More tho…
ayjlee Sep 6, 2017
f60aab0
Added a Room helper method, available_all_days?, which will be used t…
ayjlee Sep 7, 2017
107fd3a
can view a list of available rooms for a given date range and reserve…
ayjlee Sep 7, 2017
8d8ca89
Refactored reservations and making reservations to have guest_id as a…
ayjlee Sep 8, 2017
b884efd
added basic tests for making a reservation
ayjlee Sep 8, 2017
420fb74
Created Block class, which currently inherits from Reservation class.…
ayjlee Sep 8, 2017
5de0cd9
Created make_block method in BookingProgram and block_room method in …
ayjlee Sep 8, 2017
729b56f
made the reservation id a required argument to initialize a Reservati…
ayjlee Sep 8, 2017
b56ae49
Added Block to required files
ayjlee Sep 8, 2017
57c76a9
Added new BlockReservation subclass of Reservation. Block is now an i…
ayjlee Sep 8, 2017
f4a8494
Added code and logic for handling block reservations, untested.
ayjlee Sep 8, 2017
3b43cc3
Major refactor- Reservations, BlockReservation, and Blocks all hold R…
ayjlee Sep 8, 2017
7aa52b8
Renamed the Module to be the HotelBooking, and the class to Hotel to …
ayjlee Sep 8, 2017
35e687f
All waves passing, basic tests passing. Need to fix logic for Room's …
ayjlee Sep 9, 2017
6e20e8c
Refactored Room - Rooms only keep track of the IDS for reservations a…
ayjlee Sep 9, 2017
ed4d23c
Refactored all files so that all error handling happened in the Hotel…
ayjlee Sep 11, 2017
af12b8a
Finished Evaluating Responsibility Activity
ayjlee Sep 30, 2017
a4779d8
Refactored to make sure responsibility/logic to reserve a room in a b…
ayjlee Oct 2, 2017
aa4b0dd
Added comments about Hotel Design changes made to improve Single Resp…
ayjlee Oct 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs = ["lib"]
t.warning = false
t.test_files = FileList['specs/*_spec.rb']
end

task default: :test
17 changes: 17 additions & 0 deletions lib/Block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

module HotelBooking
class Block
attr_accessor :id, :guest, :check_in, :check_out, :room_ids
attr_reader :discounted_rate

def initialize(check_in,check_out,room_ids,discounted_rate,block_id)
@check_in = check_in #ruby Date object
@check_out = check_out #ruby Date object
@room_ids = room_ids
@discounted_rate = discounted_rate
@id = block_id
end

end

end
19 changes: 19 additions & 0 deletions lib/BlockReservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require_relative 'Reservation'

module HotelBooking
class BlockReservation < HotelBooking::Reservation
attr_accessor :id, :guest, :check_in, :check_out, :room, :block_id
attr_reader :all_reservations, :type

def initialize(check_in,check_out,room_id, b_res_id, block_discount, guest = nil)
super(check_in,check_out,room_id, b_res_id,block_discount, guest = nil)
@rate = block_discount
@block_id = nil
@type= :block
end #end initialize

def cost
num_nights_charged * @rate
end
end
end
157 changes: 157 additions & 0 deletions lib/Booking.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
require 'date'
require_relative 'Reservation'
require_relative 'Room'
require_relative 'Block'
module HotelBooking

class Hotel
attr_reader :all_rooms, :all_reservations, :all_blocks
NUM_STANDARD_ROOMS = 20

def initialize
@all_rooms = HotelBooking::Hotel.setup_rooms
@all_reservations = []
@all_blocks = []
end

def available_rooms(check_in,check_out, block_id = nil)

check_valid_dates(check_in,check_out)
@all_rooms.select {|room| room.available_all_days?(check_in, check_out)}
end

def make_block(check_in,check_out,room_ids,discounted_rate)
check_in_date = Date.parse(check_in)
check_out_date = Date.parse(check_out)

check_valid_dates(check_in_date,check_out_date)
check_valid_block(check_in_date,check_out_date,room_ids)

block_id = "B" + "#{@all_blocks.count + 1}"

# block_rooms = []
#
# room_ids.each do |id|
# room = find_room_by_id(id)
# block_rooms << room
# end

block = HotelBooking::Block.new(check_in_date,check_out_date,room_ids,discounted_rate,block_id)

room_ids.each do |room_id|
room= find_room_by_id(room_id)
room.block_room(check_in_date,check_out_date,block_id)
end

@all_blocks << block

end

def make_reservation(check_in,check_out,room_id, guest_id=nil)

reservation_id = (@all_reservations.count + 1)
room= find_room_by_id(room_id)
check_in_date = Date.parse(check_in)
check_out_date = Date.parse(check_out)

check_valid_dates(check_in_date,check_out_date)

if available_rooms(check_in_date,check_out_date).include?(room)

reservation = HotelBooking::Reservation.new(check_in_date,check_out_date,room_id, reservation_id)

room.reserve_room(check_in_date,check_out_date,reservation_id, guest_id)

@all_reservations << reservation
else
raise ArgumentError.new("This room is already reserved for these dates")
end

end

def make_block_reservation(block_id,room_id,guest_id = nil)
reservation_id = (@all_reservations.count + 1)
room= find_room_by_id(room_id)
block= find_block_by_id(block_id)

raise ArgumentError.new("This block does not exist") if !(@all_blocks.include?(find_block_by_id(block_id)))
raise ArgumentError.new("This room is not in the block") if !(block.room_ids.include?(room_id))

reservation = HotelBooking::BlockReservation.new(block.check_in,block.check_out,room_id, reservation_id, block.discounted_rate)
reservation.block_id = block_id

room.reserve_block_room(block_id,reservation.id, guest_id=nil)

@all_reservations << reservation

end

def find_room_by_id(room_id)
@all_rooms.each {|room| return room if room.id == room_id}

raise ArgumentError.new "Sorry, we don't have a room matching that ID number."
end

def find_res_by_date(date_str)
date_object= Date.parse(date_str)
@all_reservations.select {|reservation| ((reservation.check_in)..(reservation.check_out)).include?(date_object)}
end

def find_block_by_id(block_id)

@all_blocks.each {|block| return block if block.id == block_id}
raise ArgumentError.new "Sorry, we don't have a block matching that ID number."
end

def find_available_rooms_by_block(block_id)
block= find_block_by_id(block_id)

block_rooms = block.room_ids.map {|id| find_room_by_id(id)}

block_rooms.select {|room| room.blocks_available.include?(block_id)}
end

def check_valid_block(check_in,check_out,room_ids)
raise ArgumentError.new("Number of rooms in a block must be 5 or under") if room_ids.count > 5

available_rooms_ids = available_rooms(check_in,check_out).map {|room| room.id}

room_ids.each do |room_id|
raise ArgumentError.new("This room is already reserved for the dates provided") if !(available_rooms_ids.include?(room_id))
end

return true

end

def check_valid_dates(check_in, check_out)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love all the small helper methods you made :D I wish that there were a better place to put this specific helper method about checking if it's a valid date that wasn't in Hotel, but I can't think of a better place at the moment.

if check_in < Date.today || check_out < Date.today
raise ArgumentError.new("Can't make reservations for days earlier than today")
end

if check_in.class != Date ||check_out.class != Date
raise ArgumentError.new("Please provide a valid date")
end

if check_out < check_in
raise ArgumentError.new("Invalid Date Range: Check out date is earlier than check-in date.")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to pick a different Error besides ArgumentError (like even writing a custom Error!)

end

end

def self.setup_rooms
i = 1
standard_rooms = []

until standard_rooms.count == NUM_STANDARD_ROOMS
room = HotelBooking::Room.new(i)
standard_rooms << room
i += 1
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can probably do this same thing with

NUM_STANDARD_ROOMS.times do |index|
  room = HotelBooking::Room.new(index + 1)
  standard_rooms << room
end

or

(1..NUM_STANDARD_ROOMS).each do |index|
instead of needing to increment with i if you wanted to


return standard_rooms
end

end

end
7 changes: 7 additions & 0 deletions lib/Guest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### OPTIONAL CLASS

module Hotel
class Guest

end
end
28 changes: 28 additions & 0 deletions lib/Reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'date'
module HotelBooking

class Reservation
attr_accessor :id, :guest, :check_in, :check_out, :room_id
attr_reader :all_reservations, :type, :rate

def initialize(check_in,check_out,room_id, res_id, rate = 200, guest = nil)
@id = res_id
@check_in = check_in #ruby Date object
@check_out = check_out #ruby Date object
@room_id= room_id
@guest = guest
@rate = rate
@type= :standard
end #end initialize

def cost
num_nights_charged * @rate
end

def num_nights_charged
(check_out.mjd - check_in.mjd)
end

end

end
56 changes: 56 additions & 0 deletions lib/Room.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'date'

module HotelBooking

class Room
attr_reader :id, :nightly_rate, :type, :reserv_ids, :all_dates, :block_ids, :blocks_available

def initialize(id_number, nightly_rate = 200)
@id = id_number
@nightly_rate = nightly_rate
@type = :standard
@reserv_ids = []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are @reserv_ids for?

@block_ids = []
@all_dates = []
@blocks_available = []
end

def reserve_room(check_in,check_out,reservation_id, guest_id=nil)

(check_in...check_out).each do |date|
@all_dates << date
end

@reserv_ids << reservation_id
end

def reserve_block_room(block_id, reservation_id, guest_id=nil)
raise ArgumentError.new("This Block room is not available for this block reservation") if !(@blocks_available.include?(block_id))

@blocks_available.delete(block_id)
end


def block_room(check_in,check_out,block_id)
(check_in...check_out).each do |date|
return false if @all_dates.include?(date)
end

@blocks_available << block_id

(check_in...check_out).each do |date|
@all_dates << date
end
end

def available_all_days?(check_in, check_out)
(check_in..check_out).each do |date|
return false if @all_dates.include?(date)
end

return true
end

end

end
44 changes: 44 additions & 0 deletions specs/BlockReservation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'date'

require_relative 'spec_helper'

describe "HotelBooking::BlockReservation class" do
describe "initialize" do
it "initalizes with the appropriate reservation type" do
check_in = Date.parse("2018-10-03")
check_out = Date.parse("2018-10-06")
room_id = 1
b_res_id = 14
discounted_rate = 5
block_id = 42

new_block_res = HotelBooking::BlockReservation.new(check_in, check_out,room_id,b_res_id,discounted_rate, block_id)

new_block_res.must_be_instance_of HotelBooking::BlockReservation
new_block_res.type.must_equal :block

end
end

describe "num_nights_charged" do

it "correctly inherits the num_nights_charged method from the HotelBooking::Reservation class" do
blockres1 = HotelBooking::BlockReservation.new(Date.parse("2018-02-14"), Date.parse("2018-02-16"),3,14,5)

blockres1.num_nights_charged.must_equal 2
end
end

describe "cost" do
it "calculates cost with a discounted rate" do
discounted_rate = 5
blockres1 = HotelBooking::BlockReservation.new(Date.parse("2018-02-14"), Date.parse("2018-02-16"),14,42,discounted_rate)
blockres1.cost.must_equal 10

blockres2 = HotelBooking::BlockReservation.new(Date.parse("2018-12-01"), Date.parse("2018-12-02"),1,5,discounted_rate)

blockres2.cost.must_equal 5
end
end

end
33 changes: 33 additions & 0 deletions specs/Block_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require_relative 'spec_helper'

describe "HotelBooking::Block class " do
describe "initialize" do
before do
@check_in_str = "2018-10-03"
@check_out_str = "2018-10-06"
@new_hotel = HotelBooking::Hotel.new
@room_ids= [1,2,3]
@block_id = "Amy's Party"
@discounted_rate = 5
@new_block = HotelBooking::Block.new(Date.parse(@check_in_str), Date.parse(@check_out_str),@room_ids,@discounted_rate,@block_id)
end

it "initalizes with attributes that we can access in our booking system" do
@new_block.must_be_instance_of HotelBooking::Block

@new_block.id.must_equal @block_id
@new_block.check_in.to_s.must_equal @check_in_str
@new_block.check_out.to_s.must_equal @check_out_str

end

it "stores an array of room ids " do
@new_block.room_ids.must_be_instance_of Array
@new_block.room_ids.must_equal @room_ids
@new_block.room_ids.each do |id|
id.must_be_instance_of Integer
end
end

end
end
Loading