-
Notifications
You must be signed in to change notification settings - Fork 0
/
rolodex.rb
129 lines (86 loc) · 2.52 KB
/
rolodex.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require_relative 'contact'
class Rolodex
def initialize
@contacts =[]
@id = 1000
end
############# START ADD NEW CONTACT ###################
def add_new_contact
puts "\n"
print "Enter Name: "
name = gets.chomp
print "Enter Age: "
age = gets.chomp
print "Enter Email Address: "
email = gets.chomp
@id += 1
contact = Contact.new(@id, name, age, email)
@contacts << contact
end
############# END NEW CONTACT ########################
############# START MODIFY CONTACT ###################
def modify_contact
puts "\n"
print "Type in the contact name you would like to modify: "
name = gets.chomp.downcase
contact = find_contact(name)
print "Type in the attribute you would like to modify: "
attribute = gets.chomp
print "Type in the new attribute description: "
new_input = gets.chomp.downcase
contact.name = new_input if attribute == "name"
contact.age = new_input if attribute === "age"
contact.email = new_input if attribute == "email"
puts "\n"
end
############# END NEW CONTACT ########################
############# START DELETE CONTACT ###################
def delete_contact
puts "\n"
puts "Enter contact name you would like to delete: "
name = gets.chomp
contact = find_contact(name)
@contacts.delete(contact)
puts "\n"
puts "Contact has been deleted"
puts "\n"
end
############# END DELETE CONTACT ####################
############# START DISPLAY ALL CONTACT #############
def display_all
@contacts.each do |contact|
puts "\n"
puts "Contact ID: #{contact.id}"
puts "Name: #{contact.name}"
puts "Age: #{contact.age}"
puts "Email: #{contact.email}"
puts "\n"
end
end
############# END DISPLAY ALL CONTACT ###############
############# ADDITIONAL METHOD: FIND CONTACT (to link into 'display attribute') #############
def find_contact(name)
@contacts.select {|contact| contact.name == name}.first
end
################### END ADDITIONAL METHOD: FIND CONTACT #####################################
############# START DISPLAY ATTRIBUTE ###############
def display_attribute
print "Enter contact name that you would like to display attributes for: "
name = gets.chomp
contact = find_contact(name)
print "Enter the attribute you would like to display: "
attribute = gets.chomp
puts "\n"
if attribute == "name"
puts "#{contact.name}"
elsif attribute == "age"
puts "#{contact.age}"
elsif attribute == "email"
puts "#{contact.email}"
else
puts "you haven't put in an attribute"
end
puts "\n"
end
############# END DISPLAY ATTRIBUTE ###############
end