Class: Storytime::Importers::Wordpress
- Defined in:
- lib/storytime/importers/wordpress.rb
Instance Attribute Summary collapse
-
#xml ⇒ Object
Returns the value of attribute xml.
Attributes inherited from Importer
#creator, #file, #file_content
Instance Method Summary collapse
Methods inherited from Importer
Constructor Details
This class inherits a constructor from Storytime::Importers::Importer
Instance Attribute Details
#xml ⇒ Object
Returns the value of attribute xml.
4 5 6 |
# File 'lib/storytime/importers/wordpress.rb', line 4 def xml @xml end |
Instance Method Details
#import! ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/storytime/importers/wordpress.rb', line 6 def import! self.xml = Nokogiri::XML(file_content) posts = [] self.xml.xpath("//item").each do |item| if item.xpath(".//wp:post_type[contains(., 'post')]").length > 0 post = Storytime::BlogPost.new post.title = item.xpath("title").text post.user = creator post.content = item.xpath("content:encoded").text post.draft_content = post.content date = item.xpath("wp:post_date_gmt").text if date && !date.blank? && date != "0000-00-00 00:00:00" post.created_at = Time.strptime(date+" UTC", "%Y-%m-%d %H:%M:%S %Z") end if item.xpath("wp:status").text == "publish" pub_date = item.xpath("pubDate").text if pub_date && !pub_date.blank? post.published_at = Time.strptime(pub_date, "%a, %d %b %Y %H:%M:%S %z") end end post.save posts << post end end posts end |