-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress_book.rb
90 lines (83 loc) · 2.93 KB
/
address_book.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
require './lib/contact.rb'
require './lib/email.rb'
require './lib/address.rb'
require './lib/phone.rb'
def main_menu
current_contact = ""
puts "Address Book"
loop do
puts "Press 'a' to add a contact or 'l' to list your contacts"
user_choice = gets.chomp
case user_choice
when 'a'
puts "Enter the contact name:"
name = gets.chomp
puts "Enter an email address:"
email = gets.chomp
puts "Enter a mailing address:"
address = gets.chomp
puts "Enter a phone number:"
phone = gets.chomp
new_contact = Contact.new(name, email, address, phone)
puts "#{new_contact.name} was added."
main_menu
when 'l'
puts "The following contacts are in your address book:"
Contact.contacts.each do |contact|
puts contact.name
end
puts "Press 'v' to view a contact, 'e' to edit a contact or 'd' to delete a contact"
second_choice = gets.chomp
case second_choice
when 'v'
Contact.contacts.each do |contact|
puts "name: " + contact.name
puts "email: " + contact.email
puts "address: " + contact.address
puts "phone: " + contact.phone
end
when 'e'
Contact.contacts.each do |contact|
puts contact.name
end
puts "Enter the name of the contact that you would like to edit:"
edit_name = gets.chomp
Contact.contacts.each do |contact|
if edit_name == contact.name
current_contact = contact
puts current_contact.name
end
end
puts "Press 'n' to edit the name, 'a' to edit the address, 'e' to edit the email address, or 'p' to edit the phone number"
edit_decision = gets.chomp
case edit_decision
when "n"
puts "Enter a new name for this contact"
new_name = gets.chomp
current_contact.edit_name(new_name)
when "a"
puts "Enter a new address for this contact"
new_address = gets.chomp
current_contact.edit_address(new_address)
when "e"
puts "Enter a new email for this contact"
new_email = gets.chomp
current_contact.edit_email(new_email)
when "p"
puts "Enter a new phone for this contact"
new_phone = gets.chomp
current_contact.edit_phone(new_phone)
end
when 'd'
puts "Enter the name of the contact you'd like to delete:"
delete_name = gets.chomp
Contact.delete_contact(delete_name)
puts "These are the remaining contacts:"
Contact.contacts.each do |contact|
puts contact.name
end
end
end
end
end
main_menu