Class: Refinery::WordPress::Comment

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Comment

Returns a new instance of Comment.



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

def initialize(node) 
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



4
5
6
# File 'lib/wordpress/comment.rb', line 4

def node
  @node
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
# File 'lib/wordpress/comment.rb', line 34

def ==(other) 
  (email == other.email) && (date == other.date) && (content == other.content)
end

#approved?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/wordpress/comment.rb', line 30

def approved?
  node.xpath('wp:comment_approved').text.to_i == 1
end

#authorObject



10
11
12
# File 'lib/wordpress/comment.rb', line 10

def author
  node.xpath('wp:comment_author').text
end

#contentObject



26
27
28
# File 'lib/wordpress/comment.rb', line 26

def content
  node.xpath('wp:comment_content').text
end

#dateObject



22
23
24
# File 'lib/wordpress/comment.rb', line 22

def date
  DateTime.parse node.xpath("wp:comment_date").text
end

#emailObject



14
15
16
# File 'lib/wordpress/comment.rb', line 14

def email
  node.xpath('wp:comment_author_email').text
end

#to_refineryObject



38
39
40
41
42
43
44
45
# File 'lib/wordpress/comment.rb', line 38

def to_refinery
  comment = BlogComment.new :name => author, :email => email

  comment.body = content
  comment.created_at = date
  comment.state = approved? ? 'approved' : 'rejected'
  comment
end

#urlObject



18
19
20
# File 'lib/wordpress/comment.rb', line 18

def url
  node.xpath('wp:comment_author_url').text
end