class Library

Attributes

authors[RW]
books[RW]
orders[RW]
readers[RW]

Public Class Methods

new() click to toggle source
# File lib/library.rb, line 18
def initialize
  @books = []
  @orders = []
  @readers = []
  @authors = []
end

Public Instance Methods

find_author(author_name) click to toggle source
# File lib/library.rb, line 25
def find_author(author_name)
  found_author = authors.find { |author| author.name == author_name }
  fail "Author #{author_name} wasn't found!" unless found_author
  found_author
end
find_book(book_title) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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'
    authors.push(resourse)
  end
end