-
Notifications
You must be signed in to change notification settings - Fork 0
/
call_action.rb
58 lines (52 loc) · 1.22 KB
/
call_action.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
require_relative 'app'
require_relative './modules/write_to_file'
require_relative './modules/read_from_file'
class CallAction
include ReadFromFile
include WriteToFile
def initialize
@app = App.new
end
def call_action(choice)
case choice
when 1
@app.list_books(@app.books)
when 2
@app.list_people(@app.persons)
when 3
add_people # add student or teacher
when 4
@app.create_book(@app.books)
when 5
@app.create_rental(@app.rentals)
when 6
print 'ID of the person: '
id = gets.chomp.to_i
@app.list_rental(id)
else
puts 'Invalid option, try again!'
end
end
def add_people
puts 'Do you want to create a student (1) or a teacher(2)? [Input the number]'
choose = gets.chomp.to_i
case choose
when 1
@app.create_person(@app.persons, 'student')
when 2
@app.create_person(@app.persons, 'teacher')
else
puts 'Invalid option, try again!'
end
end
def load_data
read_book(@app.books)
read_person(@app.persons)
read_rental(@app.rentals, @app.books, @app.persons)
end
def preserve_data
write_book(@app.books)
write_person(@app.persons)
write_rental(@app.rentals)
end
end