Class: WpxmlParser::Comment

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#method_missing

Constructor Details

#initialize(entity, post) ⇒ Comment

Returns a new instance of Comment.



6
7
8
9
# File 'lib/wpxml_parser/comment.rb', line 6

def initialize(entity, post)
  super(entity)
  @post = post
end

Dynamic Method Handling

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

Class Method Details

.method_element_mapObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/wpxml_parser/comment.rb', line 11

def self.method_element_map
  { :comment_id => 'wp:comment_id',
    :author     => 'wp:comment_author',
    :email      => 'wp:comment_author_email',
    :url        => 'wp:comment_author_url',
    :ip         => 'wp:comment_author_ip',
    :date       => 'wp:comment_date',
    :date_gmt   => 'wp:comment_date_gmt',
    :body       => 'wp:comment_content',
    :approved   => 'wp:comment_approved',
    :parent_id  => 'wp:comment_parent' }
end

Instance Method Details

#approved?Boolean

Returns:

  • (Boolean)


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

def approved?
  approved == '1'
end

#childrenObject



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

def children
  @post.comments.select{|c| c.parent_id == comment_id}
end

#parentObject



24
25
26
# File 'lib/wpxml_parser/comment.rb', line 24

def parent
  @post.comments.find{|c| c.comment_id == parent_id }
end

#process_comment_id(comment_id) ⇒ Object



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

def process_comment_id(comment_id)
  comment_id.to_i
end

#process_date(date) ⇒ Object



48
49
50
# File 'lib/wpxml_parser/comment.rb', line 48

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

#process_date_gmt(date) ⇒ Object



52
53
54
# File 'lib/wpxml_parser/comment.rb', line 52

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

#process_parent_id(parent_id) ⇒ Object



40
41
42
# File 'lib/wpxml_parser/comment.rb', line 40

def process_parent_id(parent_id)
  parent_id.to_i
end