Class: PodcastFinder::Podcast
- Inherits:
-
Object
- Object
- PodcastFinder::Podcast
- Defined in:
- lib/podcast_finder/podcast.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#description ⇒ Object
Returns the value of attribute description.
-
#episodes ⇒ Object
readonly
Returns the value of attribute episodes.
-
#name ⇒ Object
Returns the value of attribute name.
-
#station ⇒ Object
Returns the value of attribute station.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #add_category(category) ⇒ Object
- #add_episode(episode) ⇒ Object
-
#initialize(podcast_hash) ⇒ Podcast
constructor
A new instance of Podcast.
- #list_data ⇒ Object
- #list_episodes ⇒ Object
- #save ⇒ Object
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
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
4 5 6 |
# File 'lib/podcast_finder/podcast.rb', line 4 def categories @categories end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/podcast_finder/podcast.rb', line 4 def description @description end |
#episodes ⇒ Object (readonly)
Returns the value of attribute episodes.
4 5 6 |
# File 'lib/podcast_finder/podcast.rb', line 4 def episodes @episodes end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/podcast_finder/podcast.rb', line 3 def name @name end |
#station ⇒ Object
Returns the value of attribute station.
4 5 6 |
# File 'lib/podcast_finder/podcast.rb', line 4 def station @station end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/podcast_finder/podcast.rb', line 3 def url @url end |
Class Method Details
.all ⇒ Object
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_data ⇒ Object
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_episodes ⇒ Object
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 |
#save ⇒ Object
51 52 53 |
# File 'lib/podcast_finder/podcast.rb', line 51 def save @@all << self end |