class Wordpress::WXR::Item

Public Instance Methods

==(other) click to toggle source
# File lib/wordpress/wxr/item.rb, line 121
def ==(other)
  self.class == other.class &&
    id == other.id
end
Also aliased as: eql?
attachments() click to toggle source
# File lib/wordpress/wxr/item.rb, line 84
def attachments
  wxr.attachments.select { |attachment| attachment.parent_id == id }
end
categories() click to toggle source
# File lib/wordpress/wxr/item.rb, line 78
def categories
  node.xpath("category[@domain='category']").map do |cat|
    wxr.categories.find_by(nicename: cat['nicename'])
  end
end
comment_status() click to toggle source
# File lib/wordpress/wxr/item.rb, line 48
def comment_status
  # TODO: `opened` or `closed`
  node.xpath('wp:comment_status').text
end
content() click to toggle source
# File lib/wordpress/wxr/item.rb, line 28
def content
  node.xpath('content:encoded').text
end
creator() click to toggle source
# File lib/wordpress/wxr/item.rb, line 20
def creator
  wxr.authors.find_by(login: node.xpath('dc:creator').text)
end
draft?() click to toggle source

TODO: status: publish, draft, pending, private, trash, inherit

# File lib/wordpress/wxr/item.rb, line 109
def draft?
  status != 'publish'
end
eql?(other)
Alias for: ==
excerpt() click to toggle source
# File lib/wordpress/wxr/item.rb, line 32
def excerpt
  node.xpath('excerpt:encoded').text
end
guid() click to toggle source
# File lib/wordpress/wxr/item.rb, line 24
def guid
  node.xpath('guid').text
end
id() click to toggle source
# File lib/wordpress/wxr/item.rb, line 36
def id
  Integer(node.xpath('wp:post_id').text)
end
meta() click to toggle source
# File lib/wordpress/wxr/item.rb, line 96
def meta
  node.xpath('wp:postmeta').each_with_object({}) { |meta, hash|
    hash[meta.xpath('wp:meta_key').text] = meta.xpath('wp:meta_value').text
  }
end
name() click to toggle source
# File lib/wordpress/wxr/item.rb, line 57
def name
  node.xpath('wp:post_name').text
end
pages() click to toggle source
# File lib/wordpress/wxr/item.rb, line 88
def pages
  wxr.pages.select { |page| page.parent_id == id }
end
parent_id() click to toggle source
# File lib/wordpress/wxr/item.rb, line 92
def parent_id
  Integer(node.xpath('wp:post_parent').text)
end
ping_status() click to toggle source
# File lib/wordpress/wxr/item.rb, line 53
def ping_status
  node.xpath('wp:ping_status').text
end
posted_at() click to toggle source
# File lib/wordpress/wxr/item.rb, line 40
def posted_at
  # Attempt to use the GMT post date since it includes a timezone.
  # Failing that, use the post_date which will use the current timezone.
  DateTime.parse(node.xpath('wp:post_date_gmt').text)
rescue ArgumentError
  DateTime.parse node.xpath('wp:post_date').text
end
published?() click to toggle source
# File lib/wordpress/wxr/item.rb, line 113
def published?
  !draft?
end
status() click to toggle source
# File lib/wordpress/wxr/item.rb, line 61
def status
  node.xpath('wp:status').text
end
sticky?() click to toggle source
# File lib/wordpress/wxr/item.rb, line 117
def sticky?
  !node.xpath('wp:is_sticky').text.to_i.zero?
end
tags() click to toggle source
# File lib/wordpress/wxr/item.rb, line 65
def tags
  # xml dump has "post_tag" for wordpress 3.1 and "tag" for 3.0
  path = if node.xpath("category[@domain='post_tag']").count > 0
           "category[@domain='post_tag']"
         else
           "category[@domain='tag']"
         end

  node.xpath(path).map do |tag_node|
    wxr.tags.find_by(slug: tag_node['nicename'])
  end
end
title() click to toggle source
# File lib/wordpress/wxr/item.rb, line 12
def title
  node.xpath('title').text
end