Class: PodcastFinder::Episode

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(episode_hash) ⇒ Episode

Returns a new instance of Episode.



7
8
9
10
11
# File 'lib/podcast_finder/episode.rb', line 7

def initialize(episode_hash)
  episode_hash.each {|key, value| self.send("#{key}=", value)}
  self.format_date
  self.save
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

Returns the value of attribute download_link.



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

def download_link
  @download_link
end

#lengthObject

Returns the value of attribute length.



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

def length
  @length
end

#podcastObject

Returns the value of attribute podcast.



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

def podcast
  @podcast
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.allObject



44
45
46
# File 'lib/podcast_finder/episode.rb', line 44

def self.all
  @@all
end

.create_from_collection(episode_array) ⇒ Object



22
23
24
# File 'lib/podcast_finder/episode.rb', line 22

def self.create_from_collection(episode_array)
  episode_array.each {|episode_hash| self.new(episode_hash)}
end

Instance Method Details

#display_dateObject



18
19
20
# File 'lib/podcast_finder/episode.rb', line 18

def display_date
  @date.strftime('%B %-d, %Y')
end

#format_dateObject



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

def format_date
  date_string = @date.to_s
  @date = Date.parse(date_string, "%Y-%m-%d")
end

#list_dataObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/podcast_finder/episode.rb', line 26

def list_data
  puts "Episode: #{self.title}".colorize(:light_blue)
  puts "Podcast: ".colorize(:light_blue) + "#{self.podcast.name}"
  puts "Date ".colorize(:light_blue) + "#{self.display_date}"
  if self.length.nil?
    puts "Length: ".colorize(:light_blue) + "Not Available"
  else
    puts "Length: ".colorize(:light_blue) + "#{self.length}"
  end
  puts "Description: ".colorize(:light_blue) + "#{self.description}"
  puts "Link to download: ".colorize(:light_blue) + "#{self.download_link}"
  puts "Link to listen:  ".colorize(:light_blue) + "#{self.podcast.url}"
end

#saveObject



40
41
42
# File 'lib/podcast_finder/episode.rb', line 40

def save
  @@all << self
end