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

Shaunna Wiens --carets #36

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fefe406
set up initial code files, spec files and rakefile
skwiens Sep 5, 2017
d843cbf
initialize room specs and code complete
skwiens Sep 5, 2017
bc40fe8
initialize reservation code and specs complete
skwiens Sep 6, 2017
25c53b0
reader method code and specs for reservation added
skwiens Sep 6, 2017
478e62b
initialize hotel and specs finished'
skwiens Sep 6, 2017
853379b
date_include? code and specs written
skwiens Sep 6, 2017
1a8635b
hotel/spec get_res_by_date code and specs added
skwiens Sep 6, 2017
9bfad5a
created pricing class and spec
skwiens Sep 6, 2017
688ea84
get_available_rooms in hotel class and ability for user to request ro…
skwiens Sep 7, 2017
ba7788f
make list of available room, still bugs on edge cases
skwiens Sep 7, 2017
611a824
wave 2 requirements complete
skwiens Sep 7, 2017
cbbed4c
block file and spec initialize created
skwiens Sep 7, 2017
52bba64
make a block added to hotel file and spec
skwiens Sep 8, 2017
62265bf
make_block method changed and block code changed to add rooms to the …
skwiens Sep 8, 2017
ab8cb65
make reservation from a block update specs to account for requirement…
skwiens Sep 8, 2017
f82db1f
all initial requirements met, now can make reservations from a block …
skwiens Sep 8, 2017
1e4a7a6
adjusted pricing method, tests for unique block id
skwiens Sep 8, 2017
a146729
created CLI ruby file and spec
skwiens Sep 8, 2017
f6b0980
get_room method added to cli
skwiens Sep 9, 2017
6a72a20
cli - change price of room per night
skwiens Sep 10, 2017
e2ccb96
view available rooms in block cli added
skwiens Sep 10, 2017
2cabb58
basic user interface works with multiple bugs
skwiens Sep 10, 2017
aa2fd76
some bugs fixed....
skwiens Sep 10, 2017
bcc9b52
cli file finished, still some bugs, no tests. cli_spec name chagnd so…
skwiens Sep 11, 2017
918005d
design-acitvity included
skwiens Sep 28, 2017
abaadea
updated design_acitivity
skwiens Sep 28, 2017
499175d
added a date_range class
skwiens Sep 29, 2017
a7b858f
description of hotel changes in design-activity
skwiens Sep 29, 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
Prev Previous commit
Next Next commit
basic user interface works with multiple bugs
skwiens committed Sep 10, 2017
commit 2cabb585c8bf45726de9e0921a279e170d095c0d
197 changes: 151 additions & 46 deletions lib/cli.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative 'hotel'
require 'terminal-table'
require 'chronic'

module Hotel
class Cli
@@ -11,51 +12,130 @@ def initialize
end

def begin
display_user_menu
choice = get_menu_option

case choice
when "A"
reserve_room
when "B"
make_block_of_rooms
when "C"
view_reservations
when "D"
view_available_rooms
when "E"
view_available_rooms_in_block
when "F"
change_room_cost
when "G"
view_rooms
else
raise ArgumentError.new "not a valid choice"
while true
display_user_menu
choice = get_menu_option

case choice
when "A"
reserve_room
when "B"
reserve_room_from_block
when "C"
make_block_of_rooms
when "D"
view_reservations
when "E"
view_all_reservations
when "F"
view_available_rooms
when "G"
view_available_rooms_in_block
when "H"
change_room_cost
when "I"
view_rooms
when "X"
abort("Thank you! Have a nice day!")
else
raise ArgumentError.new "not a valid choice"
end

end
end

def display_user_menu
puts "\nMenu Options:\n
A. Book a room
B. Book a room from a block
C. Reserve a block of rooms
D. View reservations by date
E. View all reservations
F. View available rooms
G. View available rooms in a block
H. Change the cost of a room
I. View all rooms in the hotel\n
X. Exit the program"
end

def get_menu_option
choice = nil
until choice =~ (/^[A-Ia-i]|[Xx]$/)
print "\nPlease choose an option: "
choice = $stdin.gets.chomp
end
return choice.upcase
end

### Write in option of no room preference
# choice A
def reserve_room

check_in= get_date_for("check in", Date.today)

check_out = get_date_for("check out", check_in + 1)

print "Guest Name: "
guest = gets.chomp

print "Preferred Room: "
room = get_room

hotel.make_reservation(guest, check_in, check_out, room.number)
end

# choice B
def reserve_room_from_block
block = get_block

print "Guest Name: "
guest = gets.chomp

hotel.make_reservation_from_block(guest, block.id)
end

# choice C
def make_block_of_rooms
check_in = get_date_for("check in", Date.today)

check_out = get_date_for("check out", check_in + 1)

num_rooms = get_num_rooms

block = hotel.make_block(check_in, check_out, num_rooms)

puts "Here are the rooms reserved for block ID: #{block.id}"

show_table_of_rooms(block.rooms_in_block)
end

# choice D
def view_reservations
date = get_date_for("see reservations for")
hotel.get_res_by_date(date)


show_table_of_rooms(block.rooms_in_block)
end

# choice E
def view_all_reservations
show_table_of_reservations(hotel.reservations)
end

# choice F
def view_available_rooms
beginning_date = get_date_for(
"begin")

end_date = get_date_for("end")
begin_date = get_date_for("begin", Date.today)

end_date = get_date_for("end", begin_date + 1)

available_rooms = hotel.get_available_rooms(beginning_date, end_date)

show_table_of_rooms(available_rooms)
end


####### COME BACK TO THIS TO SEE IF IT WORKS ##########
# choice G
def view_available_rooms_in_block
block = get_block

@@ -67,6 +147,7 @@ def view_available_rooms_in_block

end

# choice H
def change_room_cost
room = get_room
new_cost = get_value
@@ -78,36 +159,47 @@ def change_room_cost
view_rooms
end

# choce I
def view_rooms
puts "\nHere is a current list of the rooms and their prices: "

show_table_of_rooms(hotel.rooms)
end

def display_user_menu
puts "\nMenu Options:\n
A. Book a room
B. Reserve a block of rooms
C. View reservations
D. View available rooms
E. View available rooms in a block
F. Change the cost of a room
G. View all rooms in the hotel\n"
def get_num_rooms
num_rooms = nil
until num_rooms =~ (/[1-5]/)
print "How many rooms would you like to reserve? "
num_rooms = gets.chomp
end
return num_rooms.to_i
end

def get_date_for(action)
puts "What date would you like to #{action}?"
def get_date_for(action, must_be_after_date = nil)
date = nil

while date == nil
date = get_date(action, must_be_after_date)
end

return date.to_date
end

def get_menu_option
choice = nil
until choice =~ (/^[A-Ga-g]$/)
print "\nPlease choose an option: "
choice = $stdin.gets.chomp
def get_date(action, must_be_after_date)
begin
print "What date would you like to #{action}? "
input = gets.chomp

date = Chronic.parse(input).to_date

if (must_be_after_date != nil) && (date < must_be_after_date)
raise StandardError.new "Invalid Date"
end
rescue
puts "Invalid date"
date = nil
end
return choice
return date
end

def get_block
@@ -124,7 +216,6 @@ def get_block
end
end

########## WRITE TESTS ###########
def get_value
print "\n\tNew Cost: "
value = gets.chomp
@@ -136,7 +227,6 @@ def get_value
return value.to_i
end

########## WRITE TESTS ##############
def get_room
print "\n\tRoom Number: "
room_number = gets.chomp
@@ -157,15 +247,30 @@ def get_room
def show_table_of_rooms(rooms_arry)
table = Terminal::Table.new do |t|
t << ["Room", "Cost per night"]
rooms.each do |room|
rooms_arry.each do |room|
t << :separator
t << [room.number, room.cost_per_night]
end
end
puts table
end

def show_table_of_reservations(reservations)
table = Terminal::Table.new do |t|
t << ["Guest Name", "Check_in", "Check_out", "Room", "Block ID" ]
reservations.each do |res|
res.block_id ? block_id = res.block_id : block_id = ""

t << :separator
t << [res.guest, res.check_in, res.check_out, res.room.number, block_id]
end
end
puts table
end
end
end # end of hotel module
#



interface = Hotel::Cli.new
interface.begin
5 changes: 5 additions & 0 deletions lib/hotel.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative 'reservations'
require_relative 'rooms'
require_relative 'block'


module Hotel
@@ -38,6 +39,8 @@ def make_block(check_in, check_out, num_rooms)
raise StandardError.new "only possible to book 5 rooms in a block"
end

### Does this work to just say block.add_room?

num_rooms.times do
room = assign_room(check_in, check_out)
@blocks.each do |block_in_array|
@@ -46,6 +49,8 @@ def make_block(check_in, check_out, num_rooms)
end
end
end

return block
end


2 changes: 1 addition & 1 deletion lib/reservations.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Hotel
class Reservation

attr_reader :total_nights, :check_in, :check_out, :room, :block_id
attr_reader :total_nights, :check_in, :check_out, :room, :block_id, :guest

def initialize(guest, check_in, check_out, room, block_id = nil)
@guest = guest
36 changes: 18 additions & 18 deletions specs/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
require_relative 'spec_helper'

describe "Command Line Interface" do
before do
@interface = Hotel::Cli.new
describe "creating and beginning" do
before do
@interface = Hotel::Cli.new
end

it "can create an instance" do
@interface.must_be_instance_of Hotel::Cli
end

it "initializes with a hotel" do
@interface.hotel.must_be_instance_of Hotel::Hotel
end

it "displays_user_menu" do
@interface.must_respond_to :display_user_menu
end
end

it " can create an instance" do
@interface.must_be_instance_of Hotel::Cli
describe "show_table_of_reservations" do

end

it "initializes with a hotel" do
@interface.hotel.must_be_instance_of Hotel::Hotel
end

it "displays_user_menu" do
@interface.must_respond_to :display_user_menu
end







end