-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact_list.rb
52 lines (50 loc) · 1.64 KB
/
contact_list.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
require_relative 'contact'
require_relative 'contact_database'
require 'csv'
#Command line. Does not loop.
ARGV
case ARGV[0]
when 'help'
puts "Here is a list of available commands:"
puts " new - Create a new contact"
puts " list - List all contacts"
puts " show - Show a contact"
puts " find - Find a contact"
when 'new'
#I am too lazy to change the text of the raised error : )
puts "Please enter new contact email"
new_email = STDIN.gets.chomp
raise 'DuplicateEmail' if ContactDatabase.dupe?(new_email)
puts "Please enter new contact name"
new_name = STDIN.gets.chomp
new_number = 'pourquoi'
#Trying to add 'limitless' phone numbers...
numbers_list = []
while new_number != 'no'
puts "Add a contact number? Yes or no"
new_number = STDIN.gets.chomp.downcase
case new_number
when 'yes'
puts "What type of phone"
type_number = STDIN.gets.chomp.capitalize
puts "What is the phone number?"
phone_number = STDIN.gets.chomp.capitalize
numbers_list << {type_number => phone_number}
puts numbers_list
when 'no'
puts Contact.create(new_name, new_email, numbers_list)
end
end
when 'list'
Contact.list
when 'all'
Contact.all
when 'find'
puts results = Contact.find(ARGV[1])
raise 'NoResultsFound' if results.empty?
when 'show'
puts results = Contact.show(ARGV[1])
raise 'NoResultsFound' if results.empty?
end
# TODO: Implement command line interaction
# This should be the only file where you use puts and gets