generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperson_options.rb
95 lines (86 loc) · 2.51 KB
/
person_options.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
require_relative 'student'
require_relative 'teacher'
class PersonOptions
attr_accessor :people, :people_objects
def initialize
@people = []
@people_objects = []
end
def fill_people
@people_objects.each do |person|
if person['type'] == 'student'
student = Student.new(person['classroom'], person['age'],
person['name'], person['id'], parent_permission: person['parent_permission'])
@people.push(student)
else
teacher = Teacher.new(person['specialization'], person['age'], person['name'], person['id'])
@people.push(teacher)
end
end
end
def teacher_to_object(teacher)
{
name: teacher.name,
age: teacher.age,
specialization: teacher.specialization,
parent_permission: 'Y',
type: 'teacher',
id: teacher.id
}
end
def student_to_object(student)
{
name: student.name,
age: student.age,
classroom: student.classroom,
parent_permission: student.parent_permission,
type: 'student',
id: student.id
}
end
def list_all_people
if @people.empty?
puts "\nThere are no people to show you, but you can add some records!"
else
puts "\nWe have #{@people.count} people to show you\n"
@people.each do |person|
if person.is_a?(Student)
puts "[Student] Name: #{person.name}, ID: #{person.id}, Age: #{person.age},
Classroom: #{person.classroom}"
else
puts "[Teacher] Name: #{person.name}, ID: #{person.id}, Age: #{person.age},
Specialization: #{person.specialization}"
end
end
end
end
def create_a_student
print 'Classroom: '
classroom = gets.chomp
print 'Age: '
age = gets.chomp
print 'Name: '
name = gets.chomp
print 'Has parent permission? [Y/N]: '
parent_permission = gets.chomp
student = Student.new(classroom, age, name, generate_random_id, parent_permission: parent_permission)
@people.push(student)
@people_objects.push(student_to_object(student))
puts "\nStudent created successfully!"
end
def create_a_teacher
print 'Age: '
age = gets.chomp
print 'Name: '
name = gets.chomp
print 'Specialization: '
specialization = gets.chomp
teacher = Teacher.new(specialization, age, name, generate_random_id)
@people.push(teacher)
@people_objects.push(teacher_to_object(teacher))
puts "\nTeacher created successfully!"
end
def generate_random_id
rand(1..1000)
end
end