Class: BookReleasesCliApp::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/book_releases_cli_app/store.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#booksObject (readonly)

– self.find (store-id)–



24
25
26
# File 'lib/book_releases_cli_app/store.rb', line 24

def books
  @books
end

#nameObject

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

.allObject

– 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

– 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

– 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.author} - #{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