forked from Ada-C9/hotel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcierge.rb
392 lines (333 loc) Β· 10.6 KB
/
concierge.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#Lily Sky | Ada c9 Ampers | Hotel Project, Ruby
require_relative './lib/front_desk'
require_relative './lib/reservation'
require_relative './lib/block'
require_relative './lib/room'
# contents map - - - -
#Make
#Validate input
#Alerts
#Inspect
#Calculate
#Begin Interface
# - - - - - - - - - -
#Make
def reserve_room(gustave)
puts "π© Reserve Room π©"
puts "\nReserve a room:"
check_in, check_out = valid_dates?
begin
a = gustave.reserve_room(check_in, check_out)
rescue
puts "\n π No rooms available!"
return
end
puts "\nπ
Room " + a.room_id.to_s + " booked under Reservation ID: " + a.reservation_id.to_s
puts " from " + a.start_date.to_s + " to " + a.end_date.to_s
puts ""
gustave.save_reservations
end
def reserve_block(gustave)
puts "π Create New Block π"
puts "\nHold a block of rooms:"
print "\n Please enter the number of rooms (5 max): "
entered_rooms = gets.chomp.to_i
rooms = valid_integer?(entered_rooms)
print "\n Please enter the nightly rate: "
rate_entry = gets.chomp.to_i
rate = valid_integer?(rate_entry)
check_in, check_out = valid_dates?
begin
a = gustave.make_room_block(rooms, rate, check_in, check_out)
rescue
puts "\n π Cannot block more than 5 rooms!"
return
end
puts "\nπ
Rooms: " + a.block_rooms.to_s + " reserved under Block ID: " + a.block_id.to_s
puts " from " + a.start_date.to_s + " to " + a.end_date.to_s
puts ""
gustave.save_blocks
gustave.save_reservations
end
def claim_blocked_room(gustave)
puts "π Reserve Block Room π"
puts "\nReserve a room from a block:"
if no_blocks_alert?(gustave) == false
return
end
holds, block_id = valid_block_id?(gustave)
begin
a = gustave.reservations_with_available_rooms(block_id).first
rescue
puts "\n π No rooms left in this block!"
return
end
puts "\nπ
Room " + a.room_id.to_s + " booked under Reservation ID: " + a.reservation_id.to_s
puts " from " + a.start_date.to_s + " to " + a.end_date.to_s
gustave.book_blocked_room(block_id)
puts ""
gustave.save_reservations
end
#Validate input
def valid_integer?(input)
number = input
until input > 0
print " Please enter a valid number: "
input = gets.chomp.to_i
number = input
end
return number
end
def valid_dates?
print "\n Please enter a start date: "
r_start = gets.chomp.to_s
check_in = valid_start_date?(r_start)
print "\n Please enter an end date: "
r_end = gets.chomp.to_s
check_out = valid_end_date?(check_in, r_end)
return check_in, check_out
end
def valid_start_date?(input)
checker = Date.parse(input) rescue nil
good = input
until checker.class == Date && checker >= Date.today
print " Please enter a valid date: "
input = gets.chomp.to_s
checker = Date.parse(input) rescue nil
good = input
end
return good
end
def valid_end_date?(start, input)
checker = Date.parse(input) rescue nil
good = input
until checker.class == Date && checker > Date.parse(start)
print " Please enter a valid date: "
input = gets.chomp.to_s
checker = Date.parse(input) rescue nil
good = input
end
return good
end
def valid_reservation_id?(gustave)
print "\n Please enter a valid Reservation ID: "
answer = gets.chomp.to_i
reservation = gustave.find_reservation_by_id(answer)
until reservation != nil
print " Please enter a valid Reservation ID: "
answer = gets.chomp.to_i
reservation = gustave.find_reservation_by_id(answer)
end
return reservation
end
def valid_date?(gustave) # a booked date
print "\n Please enter a valid date: "
answer = gets.chomp.to_s
reservations = gustave.find_reservations_by_date(answer)
until reservations != nil
print " Please enter a valid date: "
answer = gets.chomp.to_s
reservations = gustave.find_reservations_by_date(answer)
end
return reservations, answer
end
def valid_block_id?(gustave)
print "\n Please enter a valid Block ID: "
answer = gets.chomp.to_i
holds = gustave.find_reservations_in_block(answer)
until answer > 0 && holds.length != 0
print " Please enter a valid Block ID: "
answer = gets.chomp.to_i
holds = gustave.find_reservations_in_block(answer)
end
return holds, answer
end
#Alerts
def no_reservations_alert?(gustave) #superfluous?
if gustave.reservations.length == 0 || (gustave.reservations.length != 0 && gustave.reservations.all? {|reservation| reservation.block_status == :AVAILABLE} == true)
puts "\nπ© No reservations on the books at this time!"
return false
else
return true
end
end
def no_blocks_alert?(gustave)
if gustave.blocks.length == 0
puts "\nπ No blocks on the books at this time!"
return false
else
return true
end
end
#Inspect
def see_all_reservations(gustave)
if no_reservations_alert?(gustave) == false
return
end
puts "\nπ© All reservations: \n"
gustave.reservations.each do |reservation|
if (reservation.block_id == nil && reservation.block_status == nil) || (reservation.block_id != nil && reservation.block_status == :UNAVAILABLE)
puts "\nReservation ID: " + reservation.reservation_id.to_s
if reservation.block_id != nil
puts " Block ID: " + reservation.block_id.to_s
end
puts " Room Number: " + reservation.room_id.to_s
puts " Nightly rate: " + reservation.cost.to_s
puts " Check-in: " + reservation.start_date.to_s
puts " Check-out: " + reservation.end_date.to_s
puts ". . . . . . . . . . . . ."
end
end
end
def see_all_blocks(gustave)
if no_blocks_alert?(gustave) == false
return
end
puts "\nπ All blocks on the calendar: "
gustave.blocks.each do |block|
puts "\nBlock ID: " + block.block_id.to_s
puts " Block rooms: " + block.block_rooms.to_s
puts " Nightly rate: " + block.cost.to_s
puts " Check-in: " + block.start_date.to_s
puts " Check-out: " + block.end_date.to_s
puts ". . . . . . . . . . . . ."
end
end
def find_reservations_by_date(gustave)
if no_reservations_alert?(gustave) == false
return
end
#VALIDATE DATE
puts "π© Find Reservations by Date π©"
reservations, answer = valid_date?(gustave)
#RETURN RESULTS
puts "\nπ© You requested " + answer.to_s + ":"
reservations.each do |reservation|
if (reservation.block_id == nil && reservation.block_status == nil) || (reservation.block_id != nil && reservation.block_status == :UNAVAILABLE)
puts "\nReservation ID: " + reservation.reservation_id.to_s
if reservation.block_id != nil
puts "Block ID: " + reservation.block_id.to_s
end
puts " Room Number: " + reservation.room_id.to_s
puts " Nightly rate: " + reservation.cost.to_s
puts " Check-in: " + reservation.start_date.to_s
puts " Check-out: " + reservation.end_date.to_s
puts ". . . . . . . . . . . . ."
end
end
puts ""
end
def find_reservation_by_reservation_id(gustave)
if no_reservations_alert?(gustave) == false
return
end
#VALIDATE INPUT
puts "π© Find Reservation by Reservation ID π©"
reservation = valid_reservation_id?(gustave)
#RETURN RESULTS
if reservation.block_status != :AVAILABLE
puts "\nπ© You requested Reservation ID: " + reservation.reservation_id.to_s + ":"
puts "\nReservation ID: " + reservation.reservation_id.to_s
if reservation.block_id != nil && reservation.block_status == :UNAVAILABLE
puts " Block ID: " + reservation.block_id.to_s
puts " Booking Status: " + reservation.block_status.to_s
end
puts " Room Number: " + reservation.room_id.to_s
puts " Nightly rate: " + reservation.cost.to_s
puts " Check-in: " + reservation.start_date.to_s
puts " Check-out: " + reservation.end_date.to_s
end
puts ""
end
def find_block_by_block_id(gustave)
if no_blocks_alert?(gustave) == false
return
end
#VALIDATE INPUT
puts "\nπ Find Block by Block ID π"
holds, answer = valid_block_id?(gustave)
#RETURN RESULTS
puts "\nπ You requested Block ID " + answer.to_s + ":"
holds.each do |hold|
puts "\nReservation ID: " + hold.reservation_id.to_s
puts " Block ID: " + hold.block_id.to_s
puts " Booking Status: " + hold.block_status.to_s
puts " Room Number: " + hold.room_id.to_s
puts " Nightly rate: " + hold.cost.to_s
puts " Check-in: " + hold.start_date.to_s
puts " Check-out: " + hold.end_date.to_s
puts ". . . . . . . . . . . . ."
end
puts ""
end
#Calculate
def calculate_costs(gustave)
if no_reservations_alert?(gustave) == false
return
end
puts "π° Calculate Total Cost π°"
#VALIDATE INPUT
reservation = valid_reservation_id?(gustave)
amount = gustave.find_cost(reservation.reservation_id)
#RETURN RESULTS
if reservation.block_id != nil && reservation.block_status == :AVAILABLE
puts "\nπ± You have not requested a complete reservation! π±"
puts "\nReservation ID: " + reservation.reservation_id.to_s + " is held for Block ID: " + reservation.block_id.to_s
puts "\nIt is currently available to reserve:"
puts " Dates: " + reservation.start_date.to_s + " to " + reservation.end_date.to_s
puts " Total: $" + amount.to_s
return
else
puts "\nπ± Cost Calculation π±"
puts "\nReservation ID: " + reservation.reservation_id.to_s
puts " Dates: " + reservation.start_date.to_s + " to " + reservation.end_date.to_s
puts " Total: $" + amount.to_s
if reservation.block_status != nil
print " Status: " + reservation.block_status.to_s
end
end
puts ""
end
#Begin Interface
concierge = Hotel::FrontDesk.new('support/reservations.csv', 'support/blocks.csv')
command = ""
while command != "NO"
puts "\nβ¨π π¨ Front Desk Portal π¨ πβ¨"
puts "- - - - - - - - - - - - - -"
puts "Please select from the listed:
A. Reserve a room
B. Hold a block of rooms
C. Reserve a room from a block
D. See all reservations
E. See all blocks
F. Find reservations by date
G. Find reservation by Reservation ID
H. Find block by Block ID
I. Calculate cost
- - - - - - - - - - - - - -"
print "\nYour choice: "
answer = gets.chomp.upcase.to_s
puts ""
if answer == "A"
reserve_room(concierge)
elsif answer == "B"
reserve_block(concierge)
elsif answer == "C"
claim_blocked_room(concierge)
elsif answer == "D"
see_all_reservations(concierge)
elsif answer == "E"
see_all_blocks(concierge)
elsif answer == "F"
find_reservations_by_date(concierge)
elsif answer == "G"
find_reservation_by_reservation_id(concierge)
elsif answer == "H"
find_block_by_block_id(concierge)
elsif answer == "I"
calculate_costs(concierge)
end
print "\nβοΈ Would you like to continue using Front Desk Portal? βοΈ
Enter any key to continue or 'no' to exit: "
command = gets.chomp.upcase
end