class WP2Middleman::Post

Attributes

post[RW]

Public Class Methods

new(nokogiri_post_doc) click to toggle source
# File lib/wp2middleman/post.rb, line 7
def initialize(nokogiri_post_doc)
  @post = nokogiri_post_doc
end

Public Instance Methods

attachment?() click to toggle source
# File lib/wp2middleman/post.rb, line 19
def attachment?
  type == 'attachment'
end
content() click to toggle source
# File lib/wp2middleman/post.rb, line 51
def content
  post.at_xpath(".//content:encoded").inner_text
end
date_published() click to toggle source
# File lib/wp2middleman/post.rb, line 31
def date_published
  Date.parse(post_date).to_s
end
date_time_published() click to toggle source
# File lib/wp2middleman/post.rb, line 35
def date_time_published
  Time.parse(post_date).strftime("%F %T")
end
field(field) click to toggle source
# File lib/wp2middleman/post.rb, line 23
def field(field)
  post.xpath(field).first.inner_text
end
post_date() click to toggle source
# File lib/wp2middleman/post.rb, line 27
def post_date
  post.xpath("wp:post_date").first.inner_text
end
published?() click to toggle source
# File lib/wp2middleman/post.rb, line 47
def published?
  status == 'publish'
end
status() click to toggle source
# File lib/wp2middleman/post.rb, line 39
def status
  post.xpath("wp:status").first.inner_text
end
tags() click to toggle source
# File lib/wp2middleman/post.rb, line 55
def tags
  tags = []
  categories = post.xpath("category")

  categories.each do |category|
    tag_name = category.css("@nicename").text

    tags.push tag_name unless tag_name == 'uncategorized'
  end

  tags
end
title() click to toggle source
# File lib/wp2middleman/post.rb, line 11
def title
  post.css('title').text
end
type() click to toggle source
# File lib/wp2middleman/post.rb, line 43
def type
  post.xpath("wp:post_type").first.inner_text
end
valid?() click to toggle source
# File lib/wp2middleman/post.rb, line 15
def valid?
  !(post_date.nil? || title.nil? || date_time_published.nil? || content.nil?)
end