class Book

Attributes

author[RW]
episode[RW]
genre[RW]
synopsis[RW]
title[RW]
url[RW]

Public Class Methods

all() click to toggle source
# File lib/podcast_book_club/book.rb, line 32
def self.all
    @@all
end
find_by_keyword(keyword) click to toggle source
# 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
new(attributes) click to toggle source
# 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.add_author(v)
            else
                self.send("#{k}=", v)
            end

        end
    end

end

Public Instance Methods

add_author(authors) click to toggle source
# File lib/podcast_book_club/book.rb, line 40
def add_author(authors)
    @author ||= []

    if authors.kind_of?(Array)
        authors.each do |a|
            author = Author.find_or_create_by_name(a)
            @author << author
            author.books << self
        end
    else
        author = Author.find_or_create_by_name(authors)
        @author << author
        author.books = self
    end

end
add_episode(episode) click to toggle source
# File lib/podcast_book_club/book.rb, line 36
def add_episode(episode)
    episode.add_book(self)
end
add_genre(genre) click to toggle source
# 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