Class: WpxmlParser::Post

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#initialize, #method_missing

Constructor Details

This class inherits a constructor from WpxmlParser::Entity

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class WpxmlParser::Entity

Class Method Details

.method_element_mapObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/wpxml_parser/post.rb', line 6

def self.method_element_map
  { :title     => 'title',
    :link      => 'link',
    :date      => 'pubDate',
    :author    => 'dc:creator',
    :body      => 'content:encoded',
    :post_id   => 'wp:post_id',
    :slug      => 'wp:post_name',
    :status    => 'wp:status',
    :post_type => 'wp:post_type' }
end

Instance Method Details

#categoriesObject



18
19
20
# File 'lib/wpxml_parser/post.rb', line 18

def categories
  @entity.xpath('category').map(&:content).uniq
end

#commentsObject



22
23
24
25
26
# File 'lib/wpxml_parser/post.rb', line 22

def comments
  @entity.xpath('wp:comment').map do |comment|
    Comment.new(comment, self)
  end.select(&:approved?)
end

#find_comment(comment_id) ⇒ Object



28
29
30
# File 'lib/wpxml_parser/post.rb', line 28

def find_comment(comment_id)
  comments.find{|c| c.comment_id == comment_id}
end

#process_date(date) ⇒ Object



32
33
34
# File 'lib/wpxml_parser/post.rb', line 32

def process_date(date)
  Time.parse(date)
end

#process_post_id(post_id) ⇒ Object



36
37
38
# File 'lib/wpxml_parser/post.rb', line 36

def process_post_id(post_id)
  post_id.to_i
end