forked from gisborne/ruby-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
book_database.rb
58 lines (53 loc) · 964 Bytes
/
book_database.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
class BookDatabase
def set_books books
@books = books
end
def get_books author
@books[author]
end
def count_books author
books = @books[author]
if books == nil
puts "No such author"
else
puts books.length
end
end
def find book
result = nil
@books.each do |author, books|
if books.include? book
result = author
end
end
if result
puts result
else
puts "No such book"
end
end
def add_book author, title
books = @books[author]
if books
if books.include? title
puts "That book is already in the system"
else
books << title
end
else
puts "No such author"
end
end
def delete_book author, title
books = @books[author]
if books
if books.include? title
books.delete title
else
puts "No such title"
end
else
puts "No such author"
end
end
end