Class: Podcast::Feed
Instance Attribute Summary collapse
-
#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.
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.
Constructor Details
#initialize ⇒ Feed
Returns a new instance of Feed.
14 15 16 17 18 |
# File 'lib/podcast.rb', line 14 def initialize @mp3s = [] @language = "English" @base = '' end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
9 10 11 |
# File 'lib/podcast.rb', line 9 def base @base end |
#description ⇒ Object
Returns the value of attribute description.
9 10 11 |
# File 'lib/podcast.rb', line 9 def description @description end |
#image ⇒ Object
Returns the value of attribute image.
9 10 11 |
# File 'lib/podcast.rb', line 9 def image @image end |
#language ⇒ Object
Returns the value of attribute language.
9 10 11 |
# File 'lib/podcast.rb', line 9 def language @language end |
#link ⇒ Object
Returns the value of attribute link.
9 10 11 |
# File 'lib/podcast.rb', line 9 def link @link end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'lib/podcast.rb', line 9 def title @title end |
Instance Method Details
#add_dir(dir) ⇒ Object
add a directory location to the podcast the directory will be recursively search for mp3 files.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/podcast.rb', line 29 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$/ ) 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
21 22 23 24 |
# File 'lib/podcast.rb', line 21 def add_mp3( file ) mp3 = Mp3File.new( file ) @mp3s.push( mp3 ) end |
#each ⇒ Object
83 84 85 86 87 |
# File 'lib/podcast.rb', line 83 def each @songs.each do |s| yield s end end |
#get_rss ⇒ Object
write the podcast file
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/podcast.rb', line 49 def get_rss() rss = RSS::Rss.new( "0.9" ) channel = RSS::Rss::Channel.new channel.title = @title channel.description = @description channel.link = @link channel.language = @language rss.channel = channel image = RSS::Rss::Channel::Image.new image.url = @image image.title = @title image.link = @link channel.image = image for mp3 in @mp3s next if ! mp3.artist item = RSS::Rss::Channel::Item.new item.title = mp3 ## add a base url if base != '' link = base + '/' + mp3.path else link = mp3.path end item.link = link item.enclosure = RSS::Rss::Channel::Item::Enclosure.new( link, mp3.length, mp3.type ) channel.items << item end return rss.to_s end |
#size ⇒ Object
the total amount of files in the podcast
44 45 46 |
# File 'lib/podcast.rb', line 44 def size @mp3s.size end |