-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooking.rb
64 lines (57 loc) · 1.42 KB
/
booking.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
require_relative "fill_database"
require_relative "helpers"
require_relative "querys"
class Booking
include FillDatabase
include Connection
include Helpers
include Querys
def initialize
fill_db
@db = Connection.connect_db
end
def start
puts "\e[H\e[2J"
welcome_message
sleep(2)
puts "\e[H\e[2J"
options_menu
input = nil
while input != "exit"
print "> ".yellow
input, option = gets.chomp.split
case input
when "1"
puts "\e[H\e[2J"
top_five_publishers
when "2"
next if validation_search(option)
a, b = option.split("=")
data = { a => b }
search_books(data)
when "3"
next if validation_count(option)
count_books(option)
when "menu"
puts "\e[H\e[2J"
options_menu
when "quit"
puts "\e[H\e[2J"
goodbye_message
break
else
puts "invalid option"
end
end
end
def validation_search(to_validate)
return true if to_validate.nil? || !to_validate.include?("=")
return true if to_validate.split("=").first.nil? || to_validate.split("=").last.nil?
return true unless ["title", "publisher", "author"].include?(to_validate.split("=").first)
end
def validation_count(to_validate)
return true if to_validate.nil? || !["author", "publisher", "genre"].include?(to_validate)
end
end
booking = Booking.new
booking.start