Class: Episode

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

Returns a new instance of Episode.



12
13
14
15
16
17
18
19
# File 'lib/podcast_book_club/episode.rb', line 12

def initialize(attributes)
  @books = []

  attributes.each do |k, v|
    self.send("#{k}=", v)
  end

end

Instance Attribute Details

#booksObject

Returns the value of attribute books.



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

def books
  @books
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

Returns the value of attribute link.



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

def link
  @link
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.allObject



21
22
23
# File 'lib/podcast_book_club/episode.rb', line 21

def self.all
  @@all
end

.find_by_date(first_date, last_date) ⇒ Object



36
37
38
# File 'lib/podcast_book_club/episode.rb', line 36

def self.find_by_date(first_date, last_date)
  self.all.select { |ep| ep.date >= first_date && ep.date <= last_date }
end

.find_by_keyword(keyword) ⇒ Object



31
32
33
# File 'lib/podcast_book_club/episode.rb', line 31

def self.find_by_keyword(keyword)
  self.all.select { |ep| ep.title.downcase.include?(keyword) }
end

Instance Method Details

#add_book(book) ⇒ Object



25
26
27
28
29
# File 'lib/podcast_book_club/episode.rb', line 25

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