Class: Library
Direct Known Subclasses
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#books ⇒ Object
Returns the value of attribute books.
-
#orders ⇒ Object
Returns the value of attribute orders.
-
#readers ⇒ Object
Returns the value of attribute readers.
Instance Method Summary collapse
- #find_author(author_name) ⇒ Object
- #find_book(book_title) ⇒ Object
- #find_reader(reader_name) ⇒ Object
-
#initialize ⇒ Library
constructor
A new instance of Library.
- #save_resource(resourse) ⇒ Object
Methods included from LibraryBackupManager
#as_yaml, included, #save_backup
Constructor Details
#initialize ⇒ Library
Returns a new instance of Library.
18 19 20 21 22 23 |
# File 'lib/library.rb', line 18 def initialize @books = [] @orders = [] @readers = [] = [] end |
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
16 17 18 |
# File 'lib/library.rb', line 16 def end |
#books ⇒ Object
Returns the value of attribute books.
16 17 18 |
# File 'lib/library.rb', line 16 def books @books end |
#orders ⇒ Object
Returns the value of attribute orders.
16 17 18 |
# File 'lib/library.rb', line 16 def orders @orders end |
#readers ⇒ Object
Returns the value of attribute readers.
16 17 18 |
# File 'lib/library.rb', line 16 def readers @readers end |
Instance Method Details
#find_author(author_name) ⇒ Object
25 26 27 28 29 |
# File 'lib/library.rb', line 25 def () = .find { || .name == } fail "Author #{author_name} wasn't found!" unless end |
#find_book(book_title) ⇒ Object
31 32 33 34 35 |
# File 'lib/library.rb', line 31 def find_book(book_title) found_book = books.find { |book| book.title == book_title } fail "Book #{book_title} wasn't found!" unless found_book found_book end |
#find_reader(reader_name) ⇒ Object
37 38 39 40 41 |
# File 'lib/library.rb', line 37 def find_reader(reader_name) found_reader = readers.find { |reader| reader.name == reader_name } fail "reader #{reader_name} wasn't found!" unless found_reader found_reader end |
#save_resource(resourse) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/library.rb', line 43 def save_resource(resourse) case resourse.class.name when 'Book' books.push(resourse) unless books.include?(resourse) when 'Order' orders.push(resourse) when 'Reader' readers.push(resourse) when 'Author' .push(resourse) end end |