Class: BookReleasesCliApp::Book

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store, attributes) ⇒ Book

Returns a new instance of Book.



6
7
8
9
10
11
12
# File 'lib/book_releases_cli_app/book.rb', line 6

def initialize(store, attributes)
  @store = store

  attributes.each do |attribute_name, attribute_value|
    self.send("#{attribute_name}=", attribute_value)
  end
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



2
3
4
# File 'lib/book_releases_cli_app/book.rb', line 2

def author
  @author
end

#detail_authorObject

Returns the value of attribute detail_author.



2
3
4
# File 'lib/book_releases_cli_app/book.rb', line 2

def detail_author
  @detail_author
end

#detail_titleObject

Returns the value of attribute detail_title.



2
3
4
# File 'lib/book_releases_cli_app/book.rb', line 2

def detail_title
  @detail_title
end

#overviewObject

Returns the value of attribute overview.



2
3
4
# File 'lib/book_releases_cli_app/book.rb', line 2

def overview
  @overview
end

#priceObject

Returns the value of attribute price.



2
3
4
# File 'lib/book_releases_cli_app/book.rb', line 2

def price
  @price
end

#release_dateObject

Returns the value of attribute release_date.



2
3
4
# File 'lib/book_releases_cli_app/book.rb', line 2

def release_date
  @release_date
end

#storeObject

Returns the value of attribute store.



2
3
4
# File 'lib/book_releases_cli_app/book.rb', line 2

def store
  @store
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/book_releases_cli_app/book.rb', line 2

def title
  @title
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'lib/book_releases_cli_app/book.rb', line 2

def type
  @type
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/book_releases_cli_app/book.rb', line 2

def url
  @url
end

Class Method Details

.allObject

save instance –



26
27
28
# File 'lib/book_releases_cli_app/book.rb', line 26

def self.all
  @@all
end

.create_from_book_collection(store, books_array) ⇒ Object

– initialize –



14
15
16
17
18
19
20
# File 'lib/book_releases_cli_app/book.rb', line 14

def self.create_from_book_collection(store, books_array)
  books = books_array.collect do |book_hash|
    book = self.new(store, book_hash)
    book.save
    book
  end
end

– store writter –



40
41
42
43
44
# File 'lib/book_releases_cli_app/book.rb', line 40

def self.print_all
  all.each.with_index(1) do |book, index|
    puts "[#{index}]. #{book.title} - #{book.author} - #{book.release_date} - #{book.type} #{book.price}"
  end
end

Instance Method Details

#saveObject

– self.create_from_book_collection –



22
23
24
# File 'lib/book_releases_cli_app/book.rb', line 22

def save
  @@all << self
end