class Workarea::Blog::Import::Wordpress::EntryParser

Public Class Methods

new(doc) click to toggle source
# File lib/workarea/blog/import/wordpress/entry_parser.rb, line 6
def initialize(doc)
  @posts = doc.xpath('//item[wp:post_type="post"]')
end

Public Instance Methods

parse() click to toggle source
# File lib/workarea/blog/import/wordpress/entry_parser.rb, line 10
def parse
  @posts.map do |post|
    {
      guid_path: guid_path(post),
      title: post_title(post),
      url: post_url(post),
      new_slug: File.basename(post_url(post)),
      published?: published?(post),
      published_date: published_date(post),
      tags: tags(post),
      author: Workarea.config.wordpress_import[:author_name],
      content: content(post),
      wordpress_hostname: wordpress_hostname(post)
    }
  end
end

Private Instance Methods

content(post) click to toggle source
# File lib/workarea/blog/import/wordpress/entry_parser.rb, line 53
def content(post)
  post.xpath('./content:encoded').inner_html
end
guid_path(post) click to toggle source
# File lib/workarea/blog/import/wordpress/entry_parser.rb, line 29
def guid_path(post)
  URI.parse(post.xpath('./guid').text).query
end
post_title(post) click to toggle source
# File lib/workarea/blog/import/wordpress/entry_parser.rb, line 33
def post_title(post)
  post.xpath('./title').text
end
post_url(post) click to toggle source
# File lib/workarea/blog/import/wordpress/entry_parser.rb, line 37
def post_url(post)
  post.xpath('./link').text
end
published?(post) click to toggle source
# File lib/workarea/blog/import/wordpress/entry_parser.rb, line 41
def published?(post)
  post.xpath('./wp:status').text == 'publish'
end
published_date(post) click to toggle source
# File lib/workarea/blog/import/wordpress/entry_parser.rb, line 45
def published_date(post)
  post.xpath('./pubDate').text.to_datetime
end
tags(post) click to toggle source
# File lib/workarea/blog/import/wordpress/entry_parser.rb, line 49
def tags(post)
  post.xpath('./category').map(&:text)
end
wordpress_hostname(post) click to toggle source
# File lib/workarea/blog/import/wordpress/entry_parser.rb, line 57
def wordpress_hostname(post)
  URI.parse(post.xpath('./link').text).hostname
end