Class: Place::Comment
- Inherits:
-
Ohm::Model
- Object
- Ohm::Model
- Place::Comment
- Defined in:
- lib/place/comment.rb
Overview
Each Comment belongs to a WorkItem and is written by a User
Class Attribute Summary collapse
-
.rules ⇒ Object
Returns the value of attribute rules.
Class Method Summary collapse
-
.find_by_cid(cid) ⇒ Object
Find a comment by a “comment-id” (es: P-1#3).
Instance Method Summary collapse
-
#cid ⇒ Object
Return a calculated cid for the comment.
-
#retrieve ⇒ Object
Retrieve a specific comment data.
Class Attribute Details
.rules ⇒ Object
Returns the value of attribute rules.
19 20 21 |
# File 'lib/place/comment.rb', line 19 def rules @rules end |
Class Method Details
.find_by_cid(cid) ⇒ Object
Find a comment by a “comment-id” (es: P-1#3)
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/place/comment.rb', line 49 def self.find_by_cid(cid) comments = self.all.select do |c| chunks = c.url.split('/') wid = chunks[-2] comment_part = chunks[-1] comment_part =~ /comment-(\d+).xml/ "#{wid}##{$1}" == cid end return comments.first if comments.size > 0 return nil end |
Instance Method Details
#cid ⇒ Object
Return a calculated cid for the comment
62 63 64 65 66 67 68 |
# File 'lib/place/comment.rb', line 62 def cid chunks = self.url.split('/') wid = chunks[-2] comment_part = chunks[-1] comment_part =~ /comment-(\d+).xml/ "#{wid}#{$1}" end |
#retrieve ⇒ Object
Retrieve a specific comment data
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/place/comment.rb', line 29 def retrieve content = IO.readlines(url).join('') doc = Nokogiri::XML(content) self.class.rules.each_pair do |k,v| tmp = doc.xpath(v) case k when 'author' self.send("#{k}=", User.find_by_name(tmp[0].content)) else self.send("#{k}=", tmp[0].content) unless tmp[0].nil? end end self.workitem = WorkItem.find_by_wid(File.dirname(self.url).split(/\//).last) self.parent = Comment.find_by_cid(self.parentComment) unless self.parentComment.nil? Place.logger.info("retrieved comement for #{self.url}") self.save end |