Class: Library

Inherits:
Object
  • Object
show all
Includes:
LibraryBackupManager
Defined in:
lib/library.rb

Direct Known Subclasses

Book

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LibraryBackupManager

#as_yaml, included, #save_backup

Constructor Details

#initializeLibrary

Returns a new instance of Library.



18
19
20
21
22
23
# File 'lib/library.rb', line 18

def initialize
  @books = []
  @orders = []
  @readers = []
  @authors = []
end

Instance Attribute Details

#authorsObject

Returns the value of attribute authors.



16
17
18
# File 'lib/library.rb', line 16

def authors
  @authors
end

#booksObject

Returns the value of attribute books.



16
17
18
# File 'lib/library.rb', line 16

def books
  @books
end

#ordersObject

Returns the value of attribute orders.



16
17
18
# File 'lib/library.rb', line 16

def orders
  @orders
end

#readersObject

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_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) ⇒ 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'
    authors.push(resourse)
  end
end