Class: Podcast::Feed
Instance Attribute Summary collapse
-
#about ⇒ Object
Returns the value of attribute about.
-
#base ⇒ Object
Returns the value of attribute base.
-
#description ⇒ Object
Returns the value of attribute description.
-
#image ⇒ Object
Returns the value of attribute image.
-
#language ⇒ Object
Returns the value of attribute language.
-
#link ⇒ Object
Returns the value of attribute link.
-
#title ⇒ Object
Returns the value of attribute title.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#add_dir(dir) ⇒ Object
add a directory location to the podcast the directory will be recursively search for mp3 files.
-
#add_mp3(file) ⇒ Object
add an mp3 file to the podcast.
- #each ⇒ Object
-
#get_rss ⇒ Object
write the podcast file.
-
#initialize ⇒ Feed
constructor
A new instance of Feed.
-
#size ⇒ Object
the total amount of files in the podcast.
- #valid? ⇒ Boolean
Constructor Details
Instance Attribute Details
#about ⇒ Object
Returns the value of attribute about.
13 14 15 |
# File 'lib/podcast.rb', line 13 def about @about end |
#base ⇒ Object
Returns the value of attribute base.
13 14 15 |
# File 'lib/podcast.rb', line 13 def base @base end |
#description ⇒ Object
Returns the value of attribute description.
13 14 15 |
# File 'lib/podcast.rb', line 13 def description @description end |
#image ⇒ Object
Returns the value of attribute image.
13 14 15 |
# File 'lib/podcast.rb', line 13 def image @image end |
#language ⇒ Object
Returns the value of attribute language.
13 14 15 |
# File 'lib/podcast.rb', line 13 def language @language end |
#link ⇒ Object
Returns the value of attribute link.
13 14 15 |
# File 'lib/podcast.rb', line 13 def link @link end |
#title ⇒ Object
Returns the value of attribute title.
13 14 15 |
# File 'lib/podcast.rb', line 13 def title @title end |
#version ⇒ Object
Returns the value of attribute version.
13 14 15 |
# File 'lib/podcast.rb', line 13 def version @version end |
Instance Method Details
#add_dir(dir) ⇒ Object
add a directory location to the podcast the directory will be recursively search for mp3 files.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/podcast.rb', line 42 def add_dir(dir) # we chdir into the directory so that file paths will be relative pwd = Dir.pwd Dir.chdir(dir) Find.find('.') do |f| if (f =~ /\.mp3$/ && File.size?(f)) f.sub!(%r{^./}, '') # remove leading './' add_mp3(f) end end # go back to original directory Dir.chdir(pwd) end |
#add_mp3(file) ⇒ Object
add an mp3 file to the podcast
26 27 28 29 30 31 32 33 |
# File 'lib/podcast.rb', line 26 def add_mp3(file) begin mp3 = Mp3File.new(file) @mp3s.push(mp3) rescue Mp3InfoError => e puts "Skipping #{file} as it has a problem: #{e}" end end |
#each ⇒ Object
101 102 103 104 105 |
# File 'lib/podcast.rb', line 101 def each @songs.each do |s| yield s end end |
#get_rss ⇒ Object
write the podcast file
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/podcast.rb', line 62 def get_rss #version = "1.0" # ["0.9", "1.0", "2.0"] version = @version content = RSS::Maker.make(@version) do |m| m.channel.title = @title m.channel.description = @description m.channel.link = @link m.channel.language = @language m.channel.about = @about m.items.do_sort = true # sort items by date m.channel.updated = Time.now.to_s m.channel. = NAME if @image != nil m.image.url = @image m.image.title = @title end for mp3 in @mp3s item = m.items.new_item item.title = mp3 ## add a base url if base != '' link = base + '/' + URI::escape(mp3.path) else link = URI::escape(mp3.path) end item.link = link item.date = mp3.mtime item.enclosure.url = link item.enclosure.length = mp3.length item.enclosure.type = mp3.type end end return content end |
#size ⇒ Object
the total amount of files in the podcast
57 58 59 |
# File 'lib/podcast.rb', line 57 def size @mp3s.size end |
#valid? ⇒ Boolean
35 36 37 |
# File 'lib/podcast.rb', line 35 def valid? title != nil && description != nil && link != nil end |