class BookReleasesCliApp::Store
Attributes
books[R]
name[RW]
Public Class Methods
all()
click to toggle source
# File lib/book_releases_cli_app/store.rb, line 42 def self.all @@all end
find(id)
click to toggle source
# File lib/book_releases_cli_app/store.rb, line 20 def self.find(id) @@all[id.to_i - 1] end
new(name, books_array)
click to toggle source
# File lib/book_releases_cli_app/store.rb, line 9 def initialize(name, books_array) @name = name @books = BookReleasesCliApp::Book.create_from_book_collection(self, books_array) #@books = books_array.collect do |book_attributes| # BookReleasesCliApp::Book.new(self, book_attributes) #end @@all << self end
print_all()
click to toggle source
# File lib/book_releases_cli_app/store.rb, line 46 def self.print_all all.each.with_index(1) do |store, index| puts "[#{index}]. #{store.name}" end end
print_books_by_store(store)
click to toggle source
# File lib/book_releases_cli_app/store.rb, line 52 def self.print_books_by_store(store) store.books.each.with_index(1) do |book, index| #puts "[#{index}]. #{book.title} - #{book.author} - #{book.release_date} - #{book.type} #{book.price}" puts "[#{index}]. #{book.title} - #{book.author} - #{book.release_date}" end end
Public Instance Methods
add_book(book)
click to toggle source
# File lib/book_releases_cli_app/store.rb, line 28 def add_book(book) if !book.is_a?(Book) raise InvalidType, "Must be a Book" else @books << book unless books.include?(book) book.store = self unless book.store == self end binding.pry end
find_book(id)
click to toggle source
# File lib/book_releases_cli_app/store.rb, line 38 def find_book(id) self.books[id.to_i - 1] end