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

Octos- Ari- Hotel #48

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
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
Empty file removed lib/.keep
Empty file.
77 changes: 77 additions & 0 deletions lib/front_desk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
require 'date'

require_relative 'reservation'
require_relative 'room'

module Hotel
class Front_desk

attr_reader :total_rooms, :reservations

ROOM_ID = (1..20)

def initialize
# an array of rooms
@total_rooms = room_generator
end

# list of all rooms
def room_generator
count = 1
ROOM_ID.each do |room|
@total_rooms << Room.new(count)
count += 1
end
end

def list_rooms
return @total_rooms
end
# list of all reservations
def reservation_data
return Hotel::Reservation.all
end

def valid_date?(str, format = "%m/%d/%Y")
Date.strptime(str,format) rescue false
end

# to create a reservation
def add_room(start_date, end_date)
if valid_date?(start_date)
if valid_date?(end_date)
new_ticket = {}
new_ticket[:ticket_id] = reservation_data.length + 1
new_ticket[:start_date] = Date.parse(start_date)
new_ticket[:end_date] = Date.parse(end_date)

@total_rooms.find do |room|

Choose a reason for hiding this comment

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

Why use find here? Could you use room.sample by itself without the find method?

new_ticket[:room_id] = room.sample
end

reservaton_data.each do |room|
unless room.overlap?(start_date, end_date)
new_ticket[:room_id] = room.room_id
end
end

reserved = Hotel::Reservation.new(new_ticket)
@reservations << reserved
return reserved
else
raise ArgumentError("INVALID END DATE")
end
else
raise ArgumentError("INVALID START DATE")
end
end


# to check availablity
def check_date(date)
# check_day = Date.parse(date)
end


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


module Hotel
class Reservation

attr_reader :ticket_id, :start_date, :end_date

def initialize(input)
@ticket_id = input[:ticket_id]
@start_date = input[:start_date]
@end_date = input[:end_date]
@room = input[:room_id]
@reservations = []

if @end_date < @start_date
raise ArgumentError('Invalid Date Range')
end

@reservations << input
end

def self.all
return @reservations
Copy link

@kariabancroft kariabancroft Mar 23, 2018

Choose a reason for hiding this comment

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

You cannot use instance variables in class methods because they refer to the overall class.

end

def overlap?(sdate, edate)
# (StartA <= EndB) and (EndA >= StartB)
return if start_date <= edate && end_date >= sdate
end

def total_cost
duration = end_date - start_date
return ((duration - 1) * 200)
end

def check_cost(ticket_number)
@reservation.each do |room|
if ticket_number == room.ticket_id
return room.total_cost
else
raise ArgumentError('INVALID TICKET NUMBER')
end
end

end



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

module Hotel
class Room


attr_reader :room_id, :date_range

def initialize(room)
@room_id = room[:room_id]
@date_range = []
#
unless Front_desk::ROOM_ID.include?(@room_id)
raise StandardError("INVALID ID")
end
end

#
# def available(start_date, end_date)
# end
#
# def add_reservation(input)
#
# end
#
end
end
Empty file removed specs/.keep
Empty file.
46 changes: 46 additions & 0 deletions specs/front_desk_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require_relative 'spec_helper'
require 'pry'


describe 'Front_desk' do

describe 'Initialize' do
it 'creates a list of 20 rooms' do
new_room = Hotel::Front_desk.new
new_room.total_rooms.must_be_kind_of Array
new_room.total_rooms.length.must_equal 20

new_room.total_rooms.each do |room|
room.must_be_instance_of Hotel::Room
end
end
it 'creates a list of reservations' do
new_room = Hotel::Front_desk.new
new_room.reservations.must_be_kind_of Array
end
end

describe 'room data' do
it 'returns a list of all rooms' do
end
admin = Hotel::Front_desk.new
room = Hotel::Room.new([1])
admin.room_data.must_respond_to room
admin.room_data.must_output 1
end

describe 'reservation data' do
it 'can return a list of reservations' do
end
end

describe 'Add Room' do
it 'can create a reservation' do
room = Hotel::Front_desk.new

new_date = room.add_room('3rd Feb 2001', '6th Feb 2001')
# new_date.must_be_instance_of Hotel::Reservation
room.reservations.must_include new_date
end
end
end
13 changes: 13 additions & 0 deletions specs/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'simplecov'
SimpleCov.start

require 'time'
require 'minitest'
require 'minitest/autorun'
require 'minitest/reporters'
require_relative '../lib/front_desk'
require_relative '../lib/room'
require_relative '../lib/reservation'
# Add simplecov

Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new