forked from AdaGold/hotel
-
Notifications
You must be signed in to change notification settings - Fork 45
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
arrriiii
wants to merge
8
commits into
Ada-C9:master
Choose a base branch
from
arrriiii:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b0c058e
Created rb files for room, reservation, front desk
arrriiii a70b24e
Initialized room class in front desk class
arrriiii c42673a
Add front_desk spec file
arrriiii 4858afe
Wave 2 tbd
arrriiii f8627cd
Added count to reservation class
arrriiii 4d9b2eb
Fixed testing for front desk class
arrriiii 3e0dd54
Test for reservation class fixed
arrriiii a85f113
Fixed Standard Error
arrriiii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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| | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 useroom.sample
by itself without thefind
method?