-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
75 lines (61 loc) · 1.78 KB
/
app.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
require './student'
require './teacher'
require './classroom'
require './rental'
require './book'
class App
attr_reader :books, :people, :rentals
attr_accessor :love
def initialize
@books = []
@people = []
@rentals = []
end
def all_book
@books&.each do |book|
puts "[#{book.class}] - Title: #{book.title}, Author: #{book.author}"
end
end
def all_person
@people&.each do |person|
puts "[#{person.class}] - Name: #{person.name}, ID: #{person.id}, Age: #{person.age}"
end
end
def all_rentals(id)
@rentals.each do |rental|
next unless rental.person.id == id
puts "[#{rental.class}] - Book: #{rental.book.title}, Person: #{rental.person.name}, Date: #{rental.date}"
end
end
def create_book(title:, author:)
@books << Book.new(title: title, author: author)
end
def create_student(id:, age:, name:, parent_permission: true, classroom: nil)
@people << Student.new(id: id, age: age, name: name, parent_permission: parent_permission, classroom: classroom)
end
def create_teacher(id:, specialization:, age:, name:, parent_permission: true)
@people << Teacher.new(id: id, specialization: specialization, age: age, name: name,
parent_permission: parent_permission)
end
def create_rental(book:, person:, date:)
@rentals << Rental.new(book: book, person: person, date: date)
end
# For test purpose
def books_to_json
@books.each { |book| puts JSON.generate(book) }
end
# For test purpose
def people_to_json
@people.each { |person| puts JSON.generate(person) }
end
# For test purpose
def rentals_to_json
@rentals.each { |rental| puts JSON.generate(rental) }
end
# For test purpose
def clear_data
@people = []
@rentals = []
@books = []
end
end