Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions lib/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Class Admin
Empty file added lib/Admin.rb
Empty file.
24 changes: 24 additions & 0 deletions lib/availability.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# require 'date'
#
# class Availibility
#
# def range
#
# rooms.each do |room, reservation|
# puts room, reservation
# end
#
# reservation.each do |time|
# range = (time[:check_in]..time[:check_out])
# end
# return range
# end
#
# def avail_rooms (room_num, time_in, time_out)
# if range.include(time_in)
# raise ArgumentError.new("This date is reserved")
# elsif range.include(time_out)
# raise ArgumentError.new("This date is reserved")
# else
# rooms[:key] = room_num
# rooms[:key].value <<
37 changes: 37 additions & 0 deletions lib/hotel_rooms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'date'

module Hotel
class HotelRooms
attr_reader :rooms, :reservations

def initialize
@rooms = [:rooms]
# fill in hotel rooms
@reservations = {}
set_up_rooms #calling this method
set_up_reservations #calling this method
end


def set_up_rooms
#creates list of hotel rooms
19.times do |room_number|
data = {}
data[:room_number] = (room_number + 1)
@rooms << Hotel::Room.new(data)
end
return @rooms
end

def list_rooms #outputs list of rooms
return @rooms
end

def set_up_reservations #sets reservation's key to room #s
@reservations = {}
@reservations.each do |key, value|

Choose a reason for hiding this comment

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

What is this method trying to do? Why have a hash of reservations and why have each element point to a list of all the rooms.

@reservations[key] = @rooms
end
return @reservations
end
end

Choose a reason for hiding this comment

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

You are missing an end check your indentation!

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

module Hotel
class Reservation
ROOMCOST = 200
attr_accessor :check_in, :check_out, :room_num
#things that only have to deal with SINGLE ROOM, one reservation at a time
#monitors overlapping
def initialize(check_in, check_out, room_num)
@check_in = check_in
@check_in = check_out
@room_num = room_num
if @room_num > 20 || @room_number < 1
raise ArgumentError.new("Number must be between 1 - 20")
end
end

def reserve_room(check_in, check_out, room_num)
#reserves a room for a given date range
in = Date.parse(check_in)

Choose a reason for hiding this comment

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

You are using a keyword here, in means something special in Ruby so you can't use it for a variable name.

out = Date.parse(check_out)
@range = (out - in)

if @reservations[@rooms.last] == room_num

Choose a reason for hiding this comment

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

I'm not sure what this if statement is trying to accomplish. I think what you want to do is loop through all your reservations and check to see if:

  1. The reservation has the same room number and
  2. The dates conflict with the dates given as arguments.

If none do, then you can create a new reservation instance and add that to the list of reservations. Otherwise indicate an error.

However this really isn't the job of an individual Reservation instance (the method here is in the wrong class). Instead making reservations is a job of some kind of booking manager. A Reservation class should describe all the things you could ask an individual reservation (does it conflict with a given date range, what's the room #, how much does it cost etc).

@reservations[room_num]
end
reservations[:room_num].value << @range
return @reservations
end


def total_cost_reservation(check_in, check_out)

Choose a reason for hiding this comment

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

👍

#total cost for a given reservation(given range)
range = Date.parse(check_out) - Date.parse(check_in)
real_range = range.to_i
date_range = real_range - 1
cost = date_range * ROOMCOST
total_cost = "$#{cost}"
return total_cost
end
13 changes: 13 additions & 0 deletions lib/room.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Hotel
class Room
#stores information about a hotel room
attr_reader :room_number

def initialize(input)
@room_number = input[:room_number]
if @room_number > 20 || @room_number < 1
raise ArgumentError.new("Number must be between 1 - 20")
end
end
end
end
Binary file added spec/.DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions spec/coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{

Choose a reason for hiding this comment

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

Don't add your coverage to github

"result": {
"covered_percent": 100.0
}
}
7 changes: 7 additions & 0 deletions spec/coverage/.resultset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"RSpec": {
"coverage": {
},
"timestamp": 1536580678
}
}
Empty file.
Loading