Class: Genre
- Inherits:
-
Object
- Object
- Genre
- 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
-
#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
- #authors ⇒ Object
-
#initialize(attributes) ⇒ Genre
constructor
A new instance of Genre.
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) ⇒ 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
#books ⇒ Object
Returns the value of attribute books.
2 3 4 |
# File 'lib/podcast_book_club/genre.rb', line 2 def books @books end |
#name ⇒ Object
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
.all ⇒ Object
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 |
#authors ⇒ Object
28 29 30 |
# File 'lib/podcast_book_club/genre.rb', line 28 def @books.map { |book| book. }.flatten.uniq end |