Class: Book

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title = nil, author = nil, summary = nil, category = nil) ⇒ Book

Returns a new instance of Book.



7
8
9
10
11
12
13
14
# File 'lib/nyt_bestsellers_cli_gem/book.rb', line 7

def initialize(title = nil, author = nil, summary = nil, category = nil)
  @title = title
  @author = author
  @summary = summary
  @category = category
  @@all << self
  add_book_to_category(category)
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



3
4
5
# File 'lib/nyt_bestsellers_cli_gem/book.rb', line 3

def author
  @author
end

#categoryObject

Returns the value of attribute category.



3
4
5
# File 'lib/nyt_bestsellers_cli_gem/book.rb', line 3

def category
  @category
end

#summaryObject

Returns the value of attribute summary.



3
4
5
# File 'lib/nyt_bestsellers_cli_gem/book.rb', line 3

def summary
  @summary
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/nyt_bestsellers_cli_gem/book.rb', line 3

def title
  @title
end

Class Method Details

.allObject



20
21
22
# File 'lib/nyt_bestsellers_cli_gem/book.rb', line 20

def self.all
  @@all
end

.find_by_title(title) ⇒ Object



24
25
26
# File 'lib/nyt_bestsellers_cli_gem/book.rb', line 24

def self.find_by_title(title)
  self.all.detect {|book| book.title == title}
end

Instance Method Details

#add_book_to_category(category) ⇒ Object



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

def add_book_to_category(category)
  Category.all.detect {|type| type.name == category}.books << self
end