Class: Wordpress::WXR::Item
Instance Method Summary
collapse
Methods inherited from Element
#initialize
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
121
122
123
124
|
# File 'lib/wordpress/wxr/item.rb', line 121
def ==(other)
self.class == other.class &&
id == other.id
end
|
#attachments ⇒ Object
84
85
86
|
# File 'lib/wordpress/wxr/item.rb', line 84
def attachments
wxr.attachments.select { |attachment| attachment.parent_id == id }
end
|
#categories ⇒ Object
78
79
80
81
82
|
# 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
|
48
49
50
51
|
# File 'lib/wordpress/wxr/item.rb', line 48
def
node.xpath('wp:comment_status').text
end
|
#content ⇒ Object
28
29
30
|
# File 'lib/wordpress/wxr/item.rb', line 28
def content
node.xpath('content:encoded').text
end
|
#creator ⇒ Object
20
21
22
|
# File 'lib/wordpress/wxr/item.rb', line 20
def creator
wxr.authors.find_by(login: node.xpath('dc:creator').text)
end
|
#draft? ⇒ Boolean
TODO: status: publish, draft, pending, private, trash, inherit
109
110
111
|
# File 'lib/wordpress/wxr/item.rb', line 109
def draft?
status != 'publish'
end
|
#excerpt ⇒ Object
32
33
34
|
# File 'lib/wordpress/wxr/item.rb', line 32
def excerpt
node.xpath('excerpt:encoded').text
end
|
#guid ⇒ Object
24
25
26
|
# File 'lib/wordpress/wxr/item.rb', line 24
def guid
node.xpath('guid').text
end
|
#id ⇒ Object
36
37
38
|
# File 'lib/wordpress/wxr/item.rb', line 36
def id
Integer(node.xpath('wp:post_id').text)
end
|
#link ⇒ Object
16
17
18
|
# File 'lib/wordpress/wxr/item.rb', line 16
def link
URI(node.xpath('link').text)
end
|
96
97
98
99
100
|
# 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 ⇒ Object
57
58
59
|
# File 'lib/wordpress/wxr/item.rb', line 57
def name
node.xpath('wp:post_name').text
end
|
#pages ⇒ Object
88
89
90
|
# File 'lib/wordpress/wxr/item.rb', line 88
def pages
wxr.pages.select { |page| page.parent_id == id }
end
|
#parent_id ⇒ Object
92
93
94
|
# File 'lib/wordpress/wxr/item.rb', line 92
def parent_id
Integer(node.xpath('wp:post_parent').text)
end
|
#ping_status ⇒ Object
53
54
55
|
# File 'lib/wordpress/wxr/item.rb', line 53
def ping_status
node.xpath('wp:ping_status').text
end
|
#posted_at ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/wordpress/wxr/item.rb', line 40
def posted_at
DateTime.parse(node.xpath('wp:post_date_gmt').text)
rescue ArgumentError
DateTime.parse node.xpath('wp:post_date').text
end
|
#published? ⇒ Boolean
113
114
115
|
# File 'lib/wordpress/wxr/item.rb', line 113
def published?
!draft?
end
|
#status ⇒ Object
61
62
63
|
# File 'lib/wordpress/wxr/item.rb', line 61
def status
node.xpath('wp:status').text
end
|
#sticky? ⇒ Boolean
117
118
119
|
# File 'lib/wordpress/wxr/item.rb', line 117
def sticky?
!node.xpath('wp:is_sticky').text.to_i.zero?
end
|
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/wordpress/wxr/item.rb', line 65
def tags
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 ⇒ Object
12
13
14
|
# File 'lib/wordpress/wxr/item.rb', line 12
def title
node.xpath('title').text
end
|