Class: Genre

Inherits:
Object
  • Object
show all
Extended by:
Findable::ClassMethods, Memorable::ClassMethods, Sortable::ClassMethods
Includes:
Memorable::InstanceMethods
Defined in:
lib/podcast_book_club/genre.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Memorable::ClassMethods

count, create, destroy_all

Methods included from Findable::ClassMethods

find_by_name, find_by_title, find_or_create_by_name, find_or_create_by_title

Methods included from Sortable::ClassMethods

sort_by_name, sort_by_title

Methods included from Memorable::InstanceMethods

#save

Constructor Details

#initialize(attributes) ⇒ Genre

Returns a new instance of Genre.



12
13
14
15
16
# File 'lib/podcast_book_club/genre.rb', line 12

def initialize(attributes)
  @books = []
  @name = attributes[:name]
  @books << attributes[:book] if attributes[:book]
end

Instance Attribute Details

#booksObject

Returns the value of attribute books.



2
3
4
# File 'lib/podcast_book_club/genre.rb', line 2

def books
  @books
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/podcast_book_club/genre.rb', line 2

def name
  @name
end

Class Method Details

.allObject



18
19
20
# File 'lib/podcast_book_club/genre.rb', line 18

def self.all
  @@all
end

Instance Method Details

#add_book(book) ⇒ Object



22
23
24
25
26
# File 'lib/podcast_book_club/genre.rb', line 22

def add_book(book)
    self.books << book unless self.books.include?(book)
    book.genre << self unless book.genre.include?(self)
    books
end

#authorsObject



28
29
30
# File 'lib/podcast_book_club/genre.rb', line 28

def authors
  @books.map { |book| book.author }.flatten.uniq
end