class PodcastFeedGen::Generator
Constants
- FILETYPES
Public Class Methods
new(working_dir: '.', config: nil)
click to toggle source
# 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
Public Instance Methods
gen!()
click to toggle source
# 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
Private Instance Methods
episodes()
click to toggle source
# File lib/podcast_feed_gen/generator.rb, line 77 def episodes files = Dir.entries(@working_dir).select {|e| FILETYPES.keys.any? {|f| e.end_with? f }} files.map do |filename| path = File.join @working_dir, filename Episode.new(path, @config) end.sort_by {|e| e[:date]} end
feed_url()
click to toggle source
# File lib/podcast_feed_gen/generator.rb, line 87 def feed_url @config[:base_url] + 'index.rss' end
load_config()
click to toggle source
# File lib/podcast_feed_gen/generator.rb, line 91 def load_config config_path = File.join @working_dir, 'podcast_feed_gen.yml' unless File.exist? config_path puts "config file '#{config_path}' not found" exit 1 end symbolize YAML.safe_load(File.read(config_path)) end