Class: PodcastFinder::Category

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#podcastsObject

Returns the value of attribute podcasts.



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

def podcasts
  @podcasts
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



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_categoriesObject



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

#saveObject



13
14
15
# File 'lib/podcast_finder/category.rb', line 13

def save
  @@all << self
end