Class: BlogLogic::Import::WordPress
- Inherits:
-
Object
- Object
- BlogLogic::Import::WordPress
- Defined in:
- lib/blog_logic/import.rb
Defined Under Namespace
Classes: Post
Instance Attribute Summary collapse
-
#source_file ⇒ Object
Returns the value of attribute source_file.
Instance Method Summary collapse
-
#initialize(file) ⇒ WordPress
constructor
A new instance of WordPress.
- #posts ⇒ Object
- #raw_posts ⇒ Object
- #source ⇒ Object
- #to(blog) ⇒ Object
Constructor Details
#initialize(file) ⇒ WordPress
Returns a new instance of WordPress.
7 8 9 |
# File 'lib/blog_logic/import.rb', line 7 def initialize(file) self.source_file = file end |
Instance Attribute Details
#source_file ⇒ Object
Returns the value of attribute source_file.
5 6 7 |
# File 'lib/blog_logic/import.rb', line 5 def source_file @source_file end |
Instance Method Details
#posts ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/blog_logic/import.rb', line 24 def posts @posts ||= [] if @posts.empty? raw_posts.each do |item| @posts << Post.new( :title => item.xpath('.//title').first.content, :date => item.xpath('.//pubDate').first.content, :content => item.xpath('.//contents').children.first.content, :summary => item.xpath('.//excerpt').first.try(:content) ) end end @posts end |
#raw_posts ⇒ Object
43 44 45 |
# File 'lib/blog_logic/import.rb', line 43 def raw_posts self.source.xpath('//item') end |
#source ⇒ Object
39 40 41 |
# File 'lib/blog_logic/import.rb', line 39 def source @source ||= Nokogiri::XML(File.open(self.source_file)) end |
#to(blog) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/blog_logic/import.rb', line 11 def to(blog) self.posts.each do |post| blog.posts.create( :title => post.title, :author => blog., :publication_date => post.publication_date, :content => post.content, :summary => post.content.truncate(255), :state => 'published' ) end end |