class BuntoImport::Importers::RSS
Public Class Methods
process(options)
click to toggle source
Process the import.
source - a URL or a local file String.
Returns nothing.
# File lib/bunto-import/importers/rss.rb, line 30 def self.process(options) source = options.fetch('source') content = "" open(source) { |s| content = s.read } rss = ::RSS::Parser.parse(content, false) raise "There doesn't appear to be any RSS items at the source (#{source}) provided." unless rss rss.items.each do |item| formatted_date = item.date.strftime('%Y-%m-%d') post_name = item.title.split(%r{ |!|/|:|&|-|$|,}).map do |i| i.downcase if i != '' end.compact.join('-') name = "#{formatted_date}-#{post_name}" header = { 'layout' => 'post', 'title' => item.title } FileUtils.mkdir_p("_posts") File.open("_posts/#{name}.html", "w") do |f| f.puts header.to_yaml f.puts "---\n\n" f.puts item.description end end end
require_deps()
click to toggle source
# File lib/bunto-import/importers/rss.rb, line 14 def self.require_deps BuntoImport.require_with_fallback(%w[ rss rss/1.0 rss/2.0 open-uri fileutils safe_yaml ]) end
specify_options(c)
click to toggle source
# File lib/bunto-import/importers/rss.rb, line 4 def self.specify_options(c) c.option 'source', '--source NAME', 'The RSS file or URL to import' end
validate(options)
click to toggle source
# File lib/bunto-import/importers/rss.rb, line 8 def self.validate(options) if options['source'].nil? abort "Missing mandatory option --source." end end