Class: Podcast::Feed

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/podcast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFeed

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

#baseObject

Returns the value of attribute base.



9
10
11
# File 'lib/podcast.rb', line 9

def base
  @base
end

#descriptionObject

Returns the value of attribute description.



9
10
11
# File 'lib/podcast.rb', line 9

def description
  @description
end

#imageObject

Returns the value of attribute image.



9
10
11
# File 'lib/podcast.rb', line 9

def image
  @image
end

#languageObject

Returns the value of attribute language.



9
10
11
# File 'lib/podcast.rb', line 9

def language
  @language
end

Returns the value of attribute link.



9
10
11
# File 'lib/podcast.rb', line 9

def link
  @link
end

#titleObject

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

#eachObject



83
84
85
86
87
# File 'lib/podcast.rb', line 83

def each
    @songs.each do |s|
        yield s
    end
end

#get_rssObject

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

#sizeObject

the total amount of files in the podcast



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

def size
    @mp3s.size
end