Module: TDiary::CommentManager
- Included in:
- Style::BaseDiary
- Defined in:
- lib/tdiary/comment_manager.rb
Instance Method Summary collapse
- #add_comment(com) ⇒ Object
- #count_comments(all = false) ⇒ Object
- #each_comment(limit = -1 )) ⇒ Object
- #each_comment_tail(limit = 3) ⇒ Object
- #each_visible_comment(limit = -1 )) ⇒ Object
- #each_visible_trackback(limit = -1 )) ⇒ Object
- #each_visible_trackback_tail(limit = 3) ⇒ Object
Instance Method Details
#add_comment(com) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/tdiary/comment_manager.rb', line 17 def add_comment( com ) @comments << com if not @last_modified or @last_modified < com.date @last_modified = com.date end com end |
#count_comments(all = false) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/tdiary/comment_manager.rb', line 25 def count_comments( all = false ) i = 0 @comments.each do |comment| i += 1 if all or comment.visible? end i end |
#each_comment(limit = -1 )) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/tdiary/comment_manager.rb', line 33 def each_comment( limit = -1 ) @comments.each_with_index do |com,idx| break if idx >= limit and limit >= 0 yield com end end |
#each_comment_tail(limit = 3) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/tdiary/comment_manager.rb', line 40 def each_comment_tail( limit = 3 ) idx = 0 comments = @comments.collect {|c| idx += 1 if c.visible? then [c, idx] else nil end }.compact s = comments.size - limit s = 0 if s < 0 for idx in s...comments.size yield comments[idx][0], comments[idx][1] # idx is start with 1. end end |
#each_visible_comment(limit = -1 )) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/tdiary/comment_manager.rb', line 57 def each_visible_comment( limit = -1 ) @comments.each_with_index do |com,idx| break if idx >= limit and limit >= 0 next unless com.visible? yield com,idx+1 # idx is start with 1. end end |
#each_visible_trackback(limit = -1 )) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tdiary/comment_manager.rb', line 65 def each_visible_trackback( limit = -1 ) i = 0 @comments.each do |com| break if i >= limit and limit >= 0 next unless /^TrackBack$/ =~ com.name next unless com.visible_true? i += 1 yield com, i end end |
#each_visible_trackback_tail(limit = 3) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/tdiary/comment_manager.rb', line 76 def each_visible_trackback_tail( limit = 3 ) i = 0 @comments.find_all {|com| com.visible_true? and /^TrackBack$/ =~ com.name }.reverse[0,limit].reverse.each do |com| i += 1 # i starts with 1. yield com,i end end |