-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rb
More file actions
56 lines (44 loc) · 1021 Bytes
/
main.rb
File metadata and controls
56 lines (44 loc) · 1021 Bytes
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
# When the program starts, ask user name
# Create a new list for a new user
# When a new list is created, it is called by the name of the user
# 1. View existing list
# 2. Create a new list for a new user
# 3. Add a new task to the list
# 4. Remove a task from the list
require_relative 'list'
require "tty-prompt"
prompt = TTY::Prompt.new
def greeting
puts "Hi!"
puts "Welcome to the To Do List app :)"
puts "What's your name?"
print "> "
end
def menu(prompt)
choices = [
{name: "View the to-do list", value: 1},
{name: "Add a task to the list", value: 2},
{name: "Remove a task from the list", value: 3},
{name: "Quit", value: 4}
]
prompt.select("Please choose an option:", choices)
end
# -------------------------------------
# main body
# -------------------------------------
system 'clear'
greeting
name = gets.strip.downcase
todo = List.new(name)
loop do
case menu(prompt)
when 1
todo.view
when 2
todo.add
when 3
todo.remove
when 4
exit
end
end