Class: WP2Middleman::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/wp2middleman/post.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nokogiri_post_doc) ⇒ Post

Returns a new instance of Post.



7
8
9
# File 'lib/wp2middleman/post.rb', line 7

def initialize(nokogiri_post_doc)
  @post = nokogiri_post_doc
end

Instance Attribute Details

#postObject

Returns the value of attribute post.



5
6
7
# File 'lib/wp2middleman/post.rb', line 5

def post
  @post
end

Instance Method Details

#attachment?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/wp2middleman/post.rb', line 19

def attachment?
  type == 'attachment'
end

#contentObject



51
52
53
# File 'lib/wp2middleman/post.rb', line 51

def content
  post.at_xpath(".//content:encoded").inner_text
end

#date_publishedObject



31
32
33
# File 'lib/wp2middleman/post.rb', line 31

def date_published
  Date.parse().to_s
end

#date_time_publishedObject



35
36
37
# File 'lib/wp2middleman/post.rb', line 35

def date_time_published
  Time.parse().strftime("%F %T")
end

#field(field) ⇒ Object



23
24
25
# File 'lib/wp2middleman/post.rb', line 23

def field(field)
  post.xpath(field).first.inner_text
end

#post_dateObject



27
28
29
# File 'lib/wp2middleman/post.rb', line 27

def 
  post.xpath("wp:post_date").first.inner_text
end

#published?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/wp2middleman/post.rb', line 47

def published?
  status == 'publish'
end

#statusObject



39
40
41
# File 'lib/wp2middleman/post.rb', line 39

def status
  post.xpath("wp:status").first.inner_text
end

#tagsObject



55
56
57
58
59
60
61
62
63
64
65
66
# 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

#titleObject



11
12
13
# File 'lib/wp2middleman/post.rb', line 11

def title
  post.css('title').text
end

#typeObject



43
44
45
# File 'lib/wp2middleman/post.rb', line 43

def type
  post.xpath("wp:post_type").first.inner_text
end

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/wp2middleman/post.rb', line 15

def valid?
  !(.nil? || title.nil? || date_time_published.nil? || content.nil?)
end