Class: PodcastFinder::Category
- Inherits:
-
Object
- Object
- PodcastFinder::Category
- Defined in:
- lib/podcast_finder/category.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#podcasts ⇒ Object
Returns the value of attribute podcasts.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #add_podcast(podcast) ⇒ Object
-
#initialize(category_hash) ⇒ Category
constructor
A new instance of Category.
- #list_podcasts(number) ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(category_hash) ⇒ Category
Returns a new instance of Category.
7 8 9 10 11 |
# File 'lib/podcast_finder/category.rb', line 7 def initialize(category_hash) category_hash.each {|key, value| self.send("#{key}=", value)} @podcasts = [] self.save end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/podcast_finder/category.rb', line 3 def name @name end |
#podcasts ⇒ Object
Returns the value of attribute podcasts.
3 4 5 |
# File 'lib/podcast_finder/category.rb', line 3 def podcasts @podcasts end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/podcast_finder/category.rb', line 3 def url @url end |
Class Method Details
.all ⇒ Object
17 18 19 |
# File 'lib/podcast_finder/category.rb', line 17 def self.all @@all end |
.create_from_collection(category_array) ⇒ Object
26 27 28 |
# File 'lib/podcast_finder/category.rb', line 26 def self.create_from_collection(category_array) category_array.each {|category_hash| self.new(category_hash)} end |
.list_categories ⇒ Object
30 31 32 33 34 |
# File 'lib/podcast_finder/category.rb', line 30 def self.list_categories self.all.each_with_index do |category, index| puts "(#{index + 1}) #{category.name}" end end |
Instance Method Details
#add_podcast(podcast) ⇒ Object
21 22 23 24 |
# File 'lib/podcast_finder/category.rb', line 21 def add_podcast(podcast) self.podcasts << podcast podcast.add_category(self) end |
#list_podcasts(number) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/podcast_finder/category.rb', line 36 def list_podcasts(number) counter = 1 + number podcast_list_count = 0 until counter > (number + 10) do if counter <= self.podcasts.size podcast = self.podcasts[counter - 1] puts "(#{counter}) #{podcast.name}" counter += 1 podcast_list_count += 1 else counter += 10 end end podcast_list_count end |
#save ⇒ Object
13 14 15 |
# File 'lib/podcast_finder/category.rb', line 13 def save @@all << self end |