Class: Postly::BlogImporter
- Inherits:
-
Object
- Object
- Postly::BlogImporter
- Defined in:
- lib/postly/blog_importer.rb
Class Method Summary collapse
- .callback_for(attr_name) ⇒ Object
- .create_post(params) ⇒ Object
- .entry_root ⇒ Object
- .import(xml, site_id) ⇒ Object
Class Method Details
.callback_for(attr_name) ⇒ Object
23 24 25 |
# File 'lib/postly/blog_importer.rb', line 23 def self.callback_for attr_name "process_#{attr_name}".to_sym end |
.create_post(params) ⇒ Object
31 32 33 34 35 |
# File 'lib/postly/blog_importer.rb', line 31 def self.create_post params post = Postly::Post.create(params) puts "Created: #{params.inspect}" post end |
.entry_root ⇒ Object
27 28 29 |
# File 'lib/postly/blog_importer.rb', line 27 def self.entry_root entity_map[:entry] end |
.import(xml, site_id) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/postly/blog_importer.rb', line 5 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 = ( item ) if respond_to? :handle_tags_for post = create_post( params.merge(:tags => ) ) handle_comments_for( post, item ) if respond_to? :handle_comments_for entries << post end end |