generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlisting.rb
46 lines (40 loc) · 1.23 KB
/
listing.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
class Listing
# Type Book
def list_books(arr)
arr.each_with_index { |book, index| puts "#{index}-) Title: \"#{book.title}\" , Author: #{book.author}" }
puts ''
end
# Type People
def loop_rental(arr)
print 'Type ID: '
id = gets.chomp.to_i
arr.each do |person|
next unless person.id == id
person.rentals.each do |rental|
puts "Date: #{rental.date}, Book \"#{rental.book.title}\" by #{rental.book.author}"
end
end
end
def empty_message
puts 'No people found matching requested type'
nil
end
# Type Student, Type Teacher
def people_list_menu(students, teachers)
puts 'Do you want to list students? (1) or a teacher? (2) [Input the number]:'
people_option = gets.chomp
case people_option
when '1'
return empty_message if students.empty?
students.each_with_index do |student, index|
puts "#{index}-) [Students] Name: #{student.name}, ID: #{student.id}, Age: #{student.age}"
end
when '2'
return empty_message if teachers.empty?
teachers.each_with_index do |teacher, index|
puts "#{index}-) [Teachers] Name: #{teacher.name}, ID: #{teacher.id}, Age: #{teacher.age}"
end
end
people_option.to_i
end
end