Class: PodcastFeedGen::Generator

Inherits:
Object
  • Object
show all
Includes:
Symbolize
Defined in:
lib/podcast_feed_gen/generator.rb

Constant Summary collapse

FILETYPES =
{
  '.mp3'  => 'audio/mpeg',
  '.m4a'  => 'audio/m4a',
  '.ogg'  => 'audio/ogg',
  '.oga'  => 'audio/ogg',
  '.flac' => 'audio/flac'
}

Instance Method Summary collapse

Methods included from Symbolize

#map_value, #symbolize

Constructor Details

#initialize(working_dir: '.', config: nil) ⇒ Generator

Returns a new instance of Generator.



20
21
22
23
# File 'lib/podcast_feed_gen/generator.rb', line 20

def initialize(working_dir: '.', config: nil)
  @working_dir = File.expand_path working_dir
  @config = config || load_config
end

Instance Method Details

#gen!Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
# File 'lib/podcast_feed_gen/generator.rb', line 25

def gen!
  builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
    xml.rss :version => "2.0", "xmlns:itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd",  "xmlns:media" => "http://search.yahoo.com/mrss/", "xmlns:atom" => "http://www.w3.org/2005/Atom" do
      xml.channel do
        xml.tag!("atom:link",  "href" => feed_url, "rel"=>"self", "type"=>"application/rss+xml") 
        xml.title @config[:title]
        xml.link feed_url
        xml.description @config[:description]
        xml.language 'en'
        xml.pubDate episodes.first[:date].rfc822
        xml.lastBuildDate episodes.first[:date].rfc822
        xml['itunes'].author @config[:author]
        xml['itunes'].keywords @config[:keywords] if @config[:keywords]
        xml['itunes'].explicit @config[:explicit] if @config[:explicit]
        # xml['itunes'].image :href => @config[:image_url]
        xml['itunes'].owner do
          xml['itunes'].name @config[:author] if @config[:author]
          xml['itunes'].email @config[:email] if @config[:email]
        end if @config[:author]
        
        xml['itunes'].block 'no'
        # xml['itunes'].category :text => 'Technology' do
        #   xml['itunes'].category :text => 'Software How-To'
        # end
        # xml['itunes'].category :text => 'Education' do
        #   xml['itunes'].category :text => 'Training'
        # end

        episodes.each do |episode|
          xml.item do
            xml.title episode[:title]
            xml.description episode[:description]
            xml.pubDate episode[:date].rfc822
            xml.enclosure :url => episode[:url], :length => episode[:size], :type => episode[:mime_type]
            xml.link episode[:url]
            xml.guid({:isPermaLink => "false"}, episode[:sha256])
            xml['itunes'].author episode[:author] || @config[:author]
            xml['itunes'].summary episode[:description]
            xml['itunes'].explicit 'no'
            xml['itunes'].duration episode[:duration] if episode[:duration]
          end
        end
      end
    end
  end
  
  builder.to_xml
  
end