Class: Podcastinator::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/podcastinator/generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feed) ⇒ Generator

Returns a new instance of Generator.



7
8
9
# File 'lib/podcastinator/generator.rb', line 7

def initialize(feed)
  @feed = feed
end

Instance Attribute Details

#feedObject

Returns the value of attribute feed.



5
6
7
# File 'lib/podcastinator/generator.rb', line 5

def feed
  @feed
end

Class Method Details

.to_xml(feed) ⇒ Object



66
67
68
# File 'lib/podcastinator/generator.rb', line 66

def self.to_xml(feed)
  new(feed).to_xml
end

Instance Method Details

#to_xmlObject



62
63
64
# File 'lib/podcastinator/generator.rb', line 62

def to_xml
  xml_builder.to_xml
end

#xml_builderObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
# File 'lib/podcastinator/generator.rb', line 11

def xml_builder
  Nokogiri::XML::Builder.new do |xml|
    xml.rss("xmlns:itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd", "version" => "2.0") do
      xml.channel do
        # Required channel attributes
        xml.title(feed.title)
        xml.link(feed.url)
        xml.description(feed.description)
        xml["itunes"].summary(feed.description)
        xml["itunes"].image(href: feed.image_url)
        xml.generator("Podcastinator #{ Podcastinator::VERSION }")

        # Optional channel attributes
        xml.language(feed.language) if feed.language
        xml.copyright(feed.copyright) if feed.copyright
        xml.subtitle(feed.subtitle) if feed.subtitle
        xml.author(feed.author) if feed.author
        xml["itunes"].keywords([ feed.keywords ].flatten.compact.join(",")) if feed.keywords

        # Owner details
        if feed.owner_name || feed.owner_email
          xml["itunes"].owner do
            xml["itunes"].name(feed.owner_name)
            xml["itunes"].email(feed.owner_email)
          end
        end

        # Category details

        # Explicit flag

        # Channel items
        feed.items.each do |item|
          xml.item do
            xml.title(item.title)
            xml["itunes"].author(item.author)
            xml["itunes"].subtitle(item.subtitle) if item.subtitle
            xml["itunes"].summary(item.summary) if item.summary
            xml["itunes"].image(href: item.image_url || feed.image_url)
            xml.enclosure(url: item.url, length: item.file_size, type: item.mime_type)
            xml.guid(item.guid, isPermaLink: item.is_guid_permalink?)
            xml.pubDate(if item.time.respond_to?(:iso8601) then item.time.iso8601 else item.time.to_s end)
            xml["itunes"].duration(item.duration.to_i)
            xml["itunes"].keywords([ item.keywords ].flatten.compact.join(",")) if item.keywords
          end
        end
      end
    end
  end
end