Class: Book
- Inherits:
-
Object
- Object
- Book
- Extended by:
- Findable::ClassMethods, Memorable::ClassMethods, Sortable::ClassMethods
- Includes:
- Memorable::InstanceMethods
- Defined in:
- lib/podcast_book_club/book.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#episode ⇒ Object
Returns the value of attribute episode.
-
#genre ⇒ Object
Returns the value of attribute genre.
-
#synopsis ⇒ Object
Returns the value of attribute synopsis.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #add_author(authors) ⇒ Object
- #add_episode(episode) ⇒ Object
- #add_genre(genre) ⇒ Object
-
#initialize(attributes) ⇒ Book
constructor
A new instance of Book.
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) ⇒ Book
Returns a new instance of Book.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/podcast_book_club/book.rb', line 11 def initialize(attributes) @episode = [] attributes.each do |k,v| unless v == nil if "#{k}" == "genre" self.add_genre(v) elsif "#{k}" == "episode" self.add_episode(v) elsif "#{k}" == "author" self.(v) else self.send("#{k}=", v) end end end end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
2 3 4 |
# File 'lib/podcast_book_club/book.rb', line 2 def @author end |
#episode ⇒ Object
Returns the value of attribute episode.
2 3 4 |
# File 'lib/podcast_book_club/book.rb', line 2 def episode @episode end |
#genre ⇒ Object
Returns the value of attribute genre.
2 3 4 |
# File 'lib/podcast_book_club/book.rb', line 2 def genre @genre end |
#synopsis ⇒ Object
Returns the value of attribute synopsis.
2 3 4 |
# File 'lib/podcast_book_club/book.rb', line 2 def synopsis @synopsis end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/podcast_book_club/book.rb', line 2 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/podcast_book_club/book.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
32 33 34 |
# File 'lib/podcast_book_club/book.rb', line 32 def self.all @@all end |
.find_by_keyword(keyword) ⇒ Object
64 65 66 |
# File 'lib/podcast_book_club/book.rb', line 64 def self.find_by_keyword(keyword) self.all.select { |book| book.title.downcase.include?(keyword) || book.synopsis.downcase.include?(keyword) unless book.synopsis == nil } end |
Instance Method Details
#add_author(authors) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/podcast_book_club/book.rb', line 40 def () @author ||= [] if .kind_of?(Array) .each do |a| = Author.find_or_create_by_name(a) @author << .books << self end else = Author.find_or_create_by_name() @author << .books = self end end |
#add_episode(episode) ⇒ Object
36 37 38 |
# File 'lib/podcast_book_club/book.rb', line 36 def add_episode(episode) episode.add_book(self) end |
#add_genre(genre) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/podcast_book_club/book.rb', line 57 def add_genre(genre) @genre ||= [] new_genre = Genre.find_or_create_by_name(genre) new_genre.add_book(self) end |