-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventReporterCLI.rb
More file actions
106 lines (81 loc) · 2.73 KB
/
Copy pathEventReporterCLI.rb
File metadata and controls
106 lines (81 loc) · 2.73 KB
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
#Dependencies
require 'csv'
require './event_data_parser'
require './queue'
require './help'
require './search'
require './attendee'
#Class Definition
class EventReporterCLI
attr_accessor :queue
EXIT_COMMANDS = ["quit", "q", "e", "x", "exit"]
ALL_COMMANDS = {"load" => "loads a new file", "help" => "shows a list of available commands",
"queue count" => "total items in the queue", "queue clear" => "empties the queue",
"queue print" => "prints to the queue", "queue print by" => "prints the specified attribute",
"queue save to" => "exports queue to a CSV", "find" => "load the queue with matching records"}
CSV_OPTIONS = {:headers => true, :header_converters => :symbol}
# @attribute = parameters[0]
# @criteria = parameters[-1]
# @command = command
# @attendees = command.attendees
def initialize
@queue = Queue.new
end
def self.valid_command?(command)
ALL_COMMANDS.keys.include?(command)
end
def self.parse_user_input(input)
[ input.first.downcase, input[1..-1] ]
end
def self.switch_by_command(command,parameters)
if command == "load"
if EventDataParser.valid_parameters_for_load?(parameters)
@attendees = EventDataParser.load(parameters.first)
else
puts "Sorry, you specified an invalid command. Use this format:"
puts "load filename.csv"
end
elsif command == "queue"
if Queue.valid_parameters_for_queue?(parameters, command)
Queue.call(parameters, command)
else
puts "Sorry, you specified an invalid command for 'queue'."
end
elsif command == "help"
if Help.valid_parameters_for_help?(parameters)
Help.for(parameters)
else
puts "Sorry, you specified an invalid command for 'help'."
end
elsif command == "find"
if Search.valid_parameters?(parameters)
Search.find(parameters, @attendees)
else
puts "Sorry, you specified an invalid command for 'find'."
end
end
end
def self.prompt_user
printf "Please enter a command > "
gets.strip.split
end
def self.run
puts "Welcome to the EventReporter"
command = ""
until EXIT_COMMANDS.include?(command)
#command == "quit" || command == "exit"
inputs = prompt_user
if inputs.any?
command, parameters = parse_user_input(inputs)
switch_by_command(command, parameters)
elsif inputs != ALL_COMMANDS.include?(command)
puts "Sorry, you specified an invalid command.\nPlease enter 'help' for a list of available commands."
# else
# puts "No command entered."
end
end
puts "Thank You, Goodbye!"
end
end
#Scripts
EventReporterCLI.run