-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirectory_ex7.rb
67 lines (59 loc) · 1.95 KB
/
directory_ex7.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
# let's put all students into an array
def input_students
# create an empty array
students = []
name = 'bart'
default = 'Not Supplied'
cohort = ["onsite", "offsite"]
# until the name is empty, repeat this code
until name.empty?
# add the student hash to the array
# get another name from the user
puts "Please enter student name"
name = gets.chomp
break if name.empty?
puts "what is your favorite hobby?"
hobby = gets.chomp
puts "what is your height?"
height = gets.chomp
puts "what is the name of the cohort your joining?"
cohort_name = gets.chomp
if cohort_name.empty? || !cohort.include?(cohort)
cohort_name = default
end
puts "what date does your cohort start?"
cohort_start = gets.chomp
if cohort_start.empty?
cohort_start = default
end
puts 'To finish, just hit return twice'
# the below shovels the above inputs into the array
students << {name: name, cohort_name: cohort_name, cohort_start: cohort_start, hobby: hobby, height: height}
puts "Now we have #{students.count} students"
end
# return the array of students
students
end
def print_header
puts "The student of Villains Academy"
puts "----------".center(20,'--')
end
def print(students)
index_counter = 0
while students.length > index_counter
puts "#{index_counter +1}.".to_s.rjust(5,'--') +" #{students[index_counter][:name].capitalize.ljust(20,'--')}"
puts "#{students[index_counter] [:cohort_name]}"
puts "#{students[index_counter][:cohort_start].capitalize.rjust(10,'--')}"+ " cohort".ljust(10,'--')
puts "#{students[index_counter][:hobby].center(20,'--')}"
puts "#{students[index_counter][:height].center(20,'--')}"
index_counter += 1
end
end
students = input_students
def print_footer(students)
puts "Overall, we have #{students.count} great students"
end
#nothing happens until we call the methods
print_header
print(students)
print_footer(students)