Sha256: 9001331eedf8109a216314b218be73f019778c2b16a8456851a585f9e3eff541
Contents?: true
Size: 1.09 KB
Versions: 3
Compression:
Stored size: 1.09 KB
Contents
module Postly class BlogImporter def self.import xml, site_id @doc = Nokogiri::HTML xml @doc.css( entry_root ).inject([]) do | entries, item | params = { :site_id => site_id } (POST_ATTRS - [:id]).each do | attr_name | params[attr_name] = case when self.respond_to?( callback_for(attr_name) ) then self.send( callback_for(attr_name), item ) when entity_map.keys.include?( attr_name ) then item.css( entity_map[attr_name] ).text else next end end tags = handle_tags_for( item ) if respond_to? :handle_tags_for post = create_post( params.merge(:tags => tags) ) handle_comments_for( post, item ) if respond_to? :handle_comments_for entries << post end end def self.callback_for attr_name "process_#{attr_name}".to_sym end def self.entry_root entity_map[:entry] end def self.create_post params post = Postly::Post.create(params) puts "Created: #{params.inspect}" post end end end
Version data entries
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
progressions-postly-0.2.2 | lib/postly/blog_importer.rb |
postly-0.2.2 | lib/postly/blog_importer.rb |
postly-0.2.1 | lib/postly/blog_importer.rb |