Class: WP2Middleman::Post
- Inherits:
-
Object
- Object
- WP2Middleman::Post
- Defined in:
- lib/wp2middleman/post.rb
Instance Attribute Summary collapse
-
#post ⇒ Object
Returns the value of attribute post.
Instance Method Summary collapse
- #attachment? ⇒ Boolean
- #content ⇒ Object
- #date_published ⇒ Object
- #date_time_published ⇒ Object
- #field(field) ⇒ Object
-
#initialize(nokogiri_post_doc) ⇒ Post
constructor
A new instance of Post.
- #post_date ⇒ Object
- #published? ⇒ Boolean
- #status ⇒ Object
- #tags ⇒ Object
- #title ⇒ Object
- #type ⇒ Object
- #valid? ⇒ Boolean
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
#post ⇒ Object
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
19 20 21 |
# File 'lib/wp2middleman/post.rb', line 19 def type == 'attachment' end |
#content ⇒ Object
51 52 53 |
# File 'lib/wp2middleman/post.rb', line 51 def content post.at_xpath(".//content:encoded").inner_text end |
#date_published ⇒ Object
31 32 33 |
# File 'lib/wp2middleman/post.rb', line 31 def date_published Date.parse(post_date).to_s end |
#date_time_published ⇒ Object
35 36 37 |
# File 'lib/wp2middleman/post.rb', line 35 def date_time_published Time.parse(post_date).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_date ⇒ Object
27 28 29 |
# File 'lib/wp2middleman/post.rb', line 27 def post_date post.xpath("wp:post_date").first.inner_text end |
#published? ⇒ Boolean
47 48 49 |
# File 'lib/wp2middleman/post.rb', line 47 def published? status == 'publish' end |
#status ⇒ Object
39 40 41 |
# File 'lib/wp2middleman/post.rb', line 39 def status post.xpath("wp:status").first.inner_text end |
#tags ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/wp2middleman/post.rb', line 55 def = [] categories = post.xpath("category") categories.each do |category| tag_name = category.css("@nicename").text .push tag_name unless tag_name == 'uncategorized' end end |
#title ⇒ Object
11 12 13 |
# File 'lib/wp2middleman/post.rb', line 11 def title post.css('title').text end |
#type ⇒ Object
43 44 45 |
# File 'lib/wp2middleman/post.rb', line 43 def type post.xpath("wp:post_type").first.inner_text end |
#valid? ⇒ Boolean
15 16 17 |
# File 'lib/wp2middleman/post.rb', line 15 def valid? !(post_date.nil? || title.nil? || date_time_published.nil? || content.nil?) end |