Class: Author
- Inherits:
-
Object
- Object
- Author
- 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
-
#books ⇒ Object
Returns the value of attribute books.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #add_book(book) ⇒ Object
- #genres ⇒ Object
-
#initialize(attributes) ⇒ Author
constructor
A new instance of Author.
Methods included from Memorable::ClassMethods
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
Methods included from Memorable::InstanceMethods
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
#books ⇒ Object
Returns the value of attribute books.
2 3 4 |
# File 'lib/podcast_book_club/author.rb', line 2 def books @books end |
#name ⇒ Object
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
.all ⇒ Object
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 |
#genres ⇒ Object
27 28 29 |
# File 'lib/podcast_book_club/author.rb', line 27 def genres @books.map { |book| book.genre }.flatten.uniq end |