forked from odesey/StudentDirectory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
student.rb
87 lines (65 loc) · 1.69 KB
/
student.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
require 'rubygems'
require 'yaml'
class Person
attr_accessor :name
attr_accessor :email
attr_accessor :github_user
attr_accessor :twitter
attr_accessor :fun_fact
def initialize
self.get_person_info
end
def self.create_person(type)
case type
when "Student"
Student.new
when "Instructor"
Instructor.new
else
nil
end
end
def get_person_info
print "What is your name? "
self.name = gets.strip.chomp
print "What is your email?"
self.email = gets.strip.chomp
print "What is your github_user?"
self.github_user = gets.strip.chomp
print "What is your twitter?"
self.twitter = gets.strip.chomp
print "What is your fun_fact?"
self.fun_fact = gets.strip.chomp
end
end
class Student < Person
attr_accessor :age
attr_accessor :eyecolour
def get_person_info
super
print "What is your age?"
self.age = gets.strip.chomp
print "What is your eyecolour"
self.eyecolour = gets.strip.chomp
end
end
class Instructor < Person
attr_accessor :instructor_type
def get_person_info
super
print "What type of instructor are you?"
self.instructor = gets.strip.chomp
end
end
@directory = ""
puts "Student Directory, v0.0.2 by Dan Garland & Mathilda"
print "Enter Student or Instructor, q to save and quit: "
while ((input = gets.strip.chomp) != 'q') do
someone = Person.create_person(input)
# Append this to our yaml file
@directory += someone.to_yaml
puts @directory
print "Enter Student or Instructor, q to save and quit: "
end
# Open a student_directory.yml YAML file and write it out on one line
File.open('student_directory.yml', 'a') { |f| f.write(@directory) }