Class: PodcastFinder::Podcast

Inherits:
Object
  • Object
show all
Defined in:
lib/podcast_finder/podcast.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(podcast_hash) ⇒ Podcast

Returns a new instance of Podcast.



8
9
10
11
12
13
14
15
# File 'lib/podcast_finder/podcast.rb', line 8

def initialize(podcast_hash)
  @name = podcast_hash[:name]
  @url = podcast_hash[:url]
  @description = nil
  @categories = []
  @episodes = []
  self.save
end

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



4
5
6
# File 'lib/podcast_finder/podcast.rb', line 4

def categories
  @categories
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/podcast_finder/podcast.rb', line 4

def description
  @description
end

#episodesObject (readonly)

Returns the value of attribute episodes.



4
5
6
# File 'lib/podcast_finder/podcast.rb', line 4

def episodes
  @episodes
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/podcast_finder/podcast.rb', line 3

def name
  @name
end

#stationObject

Returns the value of attribute station.



4
5
6
# File 'lib/podcast_finder/podcast.rb', line 4

def station
  @station
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/podcast_finder/podcast.rb', line 3

def url
  @url
end

Class Method Details

.allObject



55
56
57
# File 'lib/podcast_finder/podcast.rb', line 55

def self.all
  @@all
end

.find_by_name(name) ⇒ Object



59
60
61
# File 'lib/podcast_finder/podcast.rb', line 59

def self.find_by_name(name)
  self.all.detect {|item| item.name == name}
end

Instance Method Details

#add_category(category) ⇒ Object



17
18
19
20
21
# File 'lib/podcast_finder/podcast.rb', line 17

def add_category(category)
  if category.class == PodcastFinder::Category && !self.categories.include?(category)
    @categories << category
  end
end

#add_episode(episode) ⇒ Object



23
24
25
26
# File 'lib/podcast_finder/podcast.rb', line 23

def add_episode(episode)
  self.episodes << episode
  episode.podcast = self
end

#list_dataObject



44
45
46
47
48
# File 'lib/podcast_finder/podcast.rb', line 44

def list_data
  puts "Podcast: #{self.name}".colorize(:light_blue)
  puts "Station:".colorize(:light_blue) + "#{self.station.name}"
  puts "Description:".colorize(:light_blue) + " #{self.description}"
end

#list_episodesObject



34
35
36
37
38
# File 'lib/podcast_finder/podcast.rb', line 34

def list_episodes
  self.episodes.each_with_index do |episode, index|
    puts "(#{index + 1}) #{episode.title} - #{episode.display_date}" + "#{" - " + episode.length unless episode.length.nil?}"
  end
end

#saveObject



51
52
53
# File 'lib/podcast_finder/podcast.rb', line 51

def save
  @@all << self
end