generated from zmekonnen251/Enumerable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_items.rb
108 lines (86 loc) · 2.46 KB
/
create_items.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
96
97
98
99
100
101
102
103
104
105
106
107
108
require_relative 'teacher'
require_relative 'student'
require_relative 'rental'
require_relative 'utility'
require_relative 'book'
module CreateItems
include Utility
def create_student(people)
print 'Age: '
age = gets.chomp.to_i
print 'Name: '
name = gets.chomp
print 'Has parent permission? [Y/N]: '
parent_permission = false
case gets.chomp.downcase
when 'y'
parent_permission = true
when 'n'
parent_permission = false
else
puts('please enter [Y/N]: ')
end
id = Random.rand(1..1000)
new_student = Student.new(id, age, name, parent_permission)
people << new_student
puts('Person created successfully!')
end
def create_teacher(_people)
print 'Age: '
age = gets.chomp
print 'Name: '
name = gets.chomp
print 'Specialization: '
specialization = gets.chomp
id = Random.rand(1..1000)
new_teacher = Teacher.new(id, age, name, specialization)
@people << new_teacher
puts('Person created successfully!')
end
def create_person(people)
puts('Do you want to create a student (1) or a teacher (2) ? [Input the number]:')
category = gets.chomp
case category
when '1'
create_student(people)
when '2'
create_teacher(people)
else
puts('Please enter [1/2]: ')
end
puts('')
display_options
end
def create_book(books)
print('Title: ')
title = gets.chomp
print('Author: ')
author = gets.chomp
new_book = Book.new(title, author)
books << new_book
puts('Book created successfully')
puts('')
display_options
end
def create_rental(books, people, rentals)
puts('Select a book from the following list by number')
([email protected] - 1).each do |i|
puts("#{i}) Title: \"#{books[i].title}\", Author: #{books[i].author}")
end
selected_book_index = gets.chomp.to_i
selected_book = books[selected_book_index]
puts('Select a person from the following list by number')
(0..people.length - 1).each do |i|
puts("#{i}) [#{people[i].class.name}] Name: #{people[i].name}, Id: #{people[i].id}, Age: #{people[i].age}")
end
selected_person_index = gets.chomp.to_i
selected_person = people[selected_person_index]
print('Date (yyyy/mm/dd): ')
rental_date = gets.chomp
new_rental = Rental.new(rental_date, selected_book, selected_person)
rentals << new_rental
puts('Rental created successfully!')
puts('')
display_options
end
end