Class: BookReleasesCliApp::Store
- Inherits:
-
Object
- Object
- BookReleasesCliApp::Store
- Defined in:
- lib/book_releases_cli_app/store.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#books ⇒ Object
readonly
– self.find (store-id)–.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
-
.all ⇒ Object
– self.find_book –.
-
.find(id) ⇒ Object
– initialize –.
-
.print_all ⇒ Object
– self.all –.
-
.print_books_by_store(store) ⇒ Object
– self.print_all.
Instance Method Summary collapse
-
#add_book(book) ⇒ Object
– books reader –.
-
#find_book(id) ⇒ Object
– add_book –.
-
#initialize(name, books_array) ⇒ Store
constructor
A new instance of Store.
Constructor Details
#initialize(name, books_array) ⇒ Store
Returns a new instance of Store.
9 10 11 12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#books ⇒ Object (readonly)
– self.find (store-id)–
24 25 26 |
# File 'lib/book_releases_cli_app/store.rb', line 24 def books @books end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/book_releases_cli_app/store.rb', line 4 def name @name end |
Class Method Details
.all ⇒ Object
– self.find_book –
42 43 44 |
# File 'lib/book_releases_cli_app/store.rb', line 42 def self.all @@all end |
.find(id) ⇒ Object
– initialize –
20 21 22 |
# File 'lib/book_releases_cli_app/store.rb', line 20 def self.find(id) @@all[id.to_i - 1] end |
.print_all ⇒ Object
– self.all –
46 47 48 49 50 |
# 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) ⇒ Object
– self.print_all
52 53 54 55 56 57 |
# 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.} - #{book.release_date}" end end |
Instance Method Details
#add_book(book) ⇒ Object
– books reader –
28 29 30 31 32 33 34 35 36 |
# 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) ⇒ Object
– add_book –
38 39 40 |
# File 'lib/book_releases_cli_app/store.rb', line 38 def find_book(id) self.books[id.to_i - 1] end |