-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.rb
More file actions
81 lines (58 loc) · 1.66 KB
/
main.rb
File metadata and controls
81 lines (58 loc) · 1.66 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
##############################################################################
# File Name: main.rb
# Author: chadd williams
# Date: 4/2/2014
# Class: CS 360 Fall 2014
# Assignment: Introduction to Ruby and Git
# Purpose: A simple contact manager application (console and menu driven)
##############################################################################
require "ContactEntry.rb"
require "ContactDataStore.rb"
##############################################################################
# Function: printMenu
# Description: print menu to the screen
# Paramaeters: none
# Returned: none
##############################################################################
def printMenu
puts "***"
puts "1. Print to Screen"
puts "2. Search"
puts "3. Add Contact"
puts "4. Delete Contact"
puts "5. Write to file"
puts "6. Quit"
end
##############################################################################
# Function: getNewContact
# Description: read a new contact entry from the user
# Paramaeters: cds - the ContactDataStore to add the entry to
# Returned: none
##############################################################################
def getNewContact(cds)
print "Firstname: "
fname = gets.chomp
print "Lastname: "
lname = gets.chomp
print "Email: "
email = gets.chomp
cds.addContact(fname,lname,email)
end
# main()
if __FILE__ == $0
choice = -1
cds = ContactDataStore.new
cds.readData("data/contacts.txt")
until 6 == choice
printMenu
choice = gets.chomp.to_i
if 1 == choice
cds.printToScreen
elsif 3 == choice
getNewContact(cds)
elsif 5 == choice
cds.writeData
end
end
cds.deleteData
end