Class: Author

Inherits:
Object
  • Object
show all
Extended by:
Findable::ClassMethods, Memorable::ClassMethods, Sortable::ClassMethods
Includes:
Memorable::InstanceMethods
Defined in:
lib/podcast_book_club/author.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) ⇒ Author

Returns a new instance of Author.



11
12
13
14
15
16
17
# File 'lib/podcast_book_club/author.rb', line 11

def initialize(attributes)
    @books = []

    @name = attributes[:name]
    self.add_book(attributes[:book])

end

Instance Attribute Details

#booksObject

Returns the value of attribute books.



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

def books
  @books
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.allObject



19
20
21
# File 'lib/podcast_book_club/author.rb', line 19

def self.all
  @@all
end

Instance Method Details

#add_book(book) ⇒ Object



23
24
25
# File 'lib/podcast_book_club/author.rb', line 23

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

#genresObject



27
28
29
# File 'lib/podcast_book_club/author.rb', line 27

def genres
    @books.map { |book| book.genre }.flatten.uniq
end