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

Ampers - Sara S - Hotel #32

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
cdcf55f
add reservation class and test methods
CheerOnMars Mar 5, 2018
8587c1f
updated length method to ensure output is an integer
CheerOnMars Mar 5, 2018
f5f634c
created room class, method, and test file
CheerOnMars Mar 5, 2018
c547e7b
create spec helper
CheerOnMars Mar 5, 2018
a3fdcdd
created hotel_admin method and tests to return array of reservations …
CheerOnMars Mar 7, 2018
45907e8
updated filed names so they could be read by rake
CheerOnMars Mar 7, 2018
f1e264e
created Rakefile
CheerOnMars Mar 7, 2018
a7db229
changed name of local variage in initialize method in Room class
CheerOnMars Mar 7, 2018
4dd8d16
deleted room_specs.rb and replaced it with room_spec.rb
CheerOnMars Mar 7, 2018
f99f765
deleted reservation_specs.rb and replaced it with reservation_spec.rb…
CheerOnMars Mar 7, 2018
509fef8
add room to initialize method in reservation class, add self method f…
CheerOnMars Mar 7, 2018
3821f9e
corrected method to access reservations for a certain day
CheerOnMars Mar 8, 2018
66170d4
changed start_date and end_date to checkin_date and checkout_date
CheerOnMars Mar 8, 2018
de77f64
adjusted variable names in lib/hotel_admin.rb for added clarity
CheerOnMars Mar 8, 2018
daddef4
updated tests for HotelAdmin's method of returning rooms
CheerOnMars Mar 8, 2018
3680efe
adjusted variable names in lib/room.rb for added clarity
CheerOnMars Mar 8, 2018
883b1a1
adjusted method names in lib/reservation.rb for added clarity
CheerOnMars Mar 8, 2018
ca4ff0d
updated tests to account for adjusted method names in lib/reservation…
CheerOnMars Mar 8, 2018
44b474c
rearranged order of hotel_admin tests
CheerOnMars Mar 8, 2018
ee581ee
rearrange order of methods
CheerOnMars Mar 8, 2018
3aee111
removed room class and specs, added room to HotelAdmin class. updated…
CheerOnMars Mar 9, 2018
32815d1
updated reservation class to grey out lines that parsed the date into…
CheerOnMars Mar 12, 2018
c633a11
add test to HotelAdmin class to check that returns a list of all the …
CheerOnMars Mar 12, 2018
de23dda
In HotelAdmin class, added method to view available rooms, and change…
CheerOnMars Mar 12, 2018
9fef03e
removed unnecessary comments
CheerOnMars Mar 12, 2018
779da5c
removed unnecessary comments and added reserve_available_room method …
CheerOnMars Mar 12, 2018
a217f7e
removed unnecessary comments and added tests for reserve_available_ro…
CheerOnMars Mar 12, 2018
21fbb57
trimmed down the tests for the HotelAdmin class's methods
CheerOnMars Mar 12, 2018
5982f91
add block class lib and spec files
CheerOnMars Mar 12, 2018
474e97d
added lib/block and removed lib/room as required relatives
CheerOnMars Mar 12, 2018
428a5a9
removed lib/room as required relative
CheerOnMars Mar 12, 2018
edb3810
holding off on making block its own class for now
CheerOnMars Mar 12, 2018
a0042c2
holding off on making block its own class for now
CheerOnMars Mar 12, 2018
ba3c378
small format change
CheerOnMars Mar 12, 2018
9c6e3e4
updated HotelAdmin class and its tests to include block functionality
CheerOnMars Mar 12, 2018
60231d0
add status to reservation class
CheerOnMars Mar 12, 2018
74b830f
update method for room holds, add appropriate tests
CheerOnMars Mar 12, 2018
d217828
removed unncessary status and price_night methods
CheerOnMars Mar 14, 2018
d2e68c9
added missing comma
CheerOnMars Mar 14, 2018
f728d7d
added party_name to reservations class
CheerOnMars Mar 14, 2018
f8ac9ef
tried to update status
CheerOnMars Mar 14, 2018
6c512e0
tried to update method and tests to reserve a room in a block
CheerOnMars Mar 14, 2018
256953b
corrected design-activity
CheerOnMars Apr 2, 2018
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 = true
t.test_files = FileList['specs/*_spec.rb']
end

task default: :test
38 changes: 38 additions & 0 deletions lib/block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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
116 changes: 116 additions & 0 deletions lib/hotel_admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
require 'time'
require_relative 'reservation'

module Hotel
class HotelAdmin
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)
#note: this is tightly coupled, I think.
@reservations << reservation
@reservation = reservation

Choose a reason for hiding this comment

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

Why set this as an instance variable here?

return @reservation
end

def calc_reservations(reservation)
reservation.price_night * reservation.calc_duration

Choose a reason for hiding this comment

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

I think this logic would be better inside the reservation object

end

def access_reservations(day)
days_reservations = []
@reservations.each do |reservation|
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)
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

def create_block(input)

if input[:block_start_date] == nil || input[:block_end_date] == nil

Choose a reason for hiding this comment

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

All of this data validation should be in an initialize somewhere

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_amt = input[:room_amt]
@block_name = input[:group_name]
@blocks << input
@block = input
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", group_name: input[:group_name]}))
@rooms_held << avail_room
@holds_reservations << new_res
end
return @block
end

def return_blocks_rooms(input)
@rooms_held
end

def return_held_reservations
@holds_reservations
end

def check_block_availability(group_name)
arr_available_held_rooms = []
@holds_reservations
@holds_reservations.each do |res|
if res.status == "held" && res.party_name == group_name
arr_available_held_rooms << res
end
end
return arr_available_held_rooms
end

def reserve_room_in_block(group_name)
block_res = check_block_availability(group_name)[0]
block_res.status = "booked"
end
end
end
35 changes: 35 additions & 0 deletions lib/reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'time'

module Hotel
class Reservation
attr_reader :checkin_date, :checkout_date, :room_id, :price_night, :party_name
attr_accessor :status

def initialize(input)

if input[:checkin_date] == nil || input[:checkout_date] == nil
raise ArgumentError.new("Date must be a date.")
end

if input[:checkin_date] >= input[:checkout_date]
raise ArgumentError.new("End date must be after start date.")
end

@checkin_date = input[:checkin_date]
@checkout_date = input[:checkout_date]
@room_id = input[:room_id]
@price_night = 200
@status = input[:status]
@party_name = input[:group_name]
end

def status
return @status
end

def calc_duration
((checkin_date...checkout_date).map{ |date| date}).count
end

end
end
16 changes: 16 additions & 0 deletions lib/room.rb
Original file line number Diff line number Diff line change
@@ -0,0 +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
71 changes: 71 additions & 0 deletions specs/block_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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
Loading