Class: Uniword::Review::ReviewManager
- Inherits:
-
Object
- Object
- Uniword::Review::ReviewManager
- Defined in:
- lib/uniword/review/review_manager.rb
Overview
Orchestrator for comments and tracked changes in a document.
Provides a unified API for listing, adding, resolving, and removing comments, as well as listing and accepting/rejecting tracked changes.
Delegates individual revision operations to AcceptReject.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
-
#accept(revision_id) ⇒ Boolean
Accept a single revision by ID.
-
#accept_all ⇒ Integer
Accept all tracked changes in the document.
-
#add_comment(text:, author:, initials: nil) ⇒ Uniword::Comment
Add a new comment to the document.
-
#all_authors ⇒ Array<String>
Get all unique authors who have made changes.
-
#clear_comments ⇒ void
Remove all comments from the document.
-
#initialize(document) ⇒ ReviewManager
constructor
Initialize a ReviewManager for the given document.
-
#list_comments ⇒ Array<Uniword::Comment>
List all comments in the document.
-
#list_revisions ⇒ Array<Uniword::Revision>
List all revisions (tracked changes) in the document.
-
#reject(revision_id) ⇒ Boolean
Reject a single revision by ID.
-
#reject_all ⇒ Integer
Reject all tracked changes in the document.
-
#remove_comment(comment_id) ⇒ Uniword::Comment?
Remove a comment from the document.
-
#reply_to_comment(parent_id, text:, author:) ⇒ Uniword::Comment
Reply to an existing comment.
-
#resolve_comment(comment_id) ⇒ Uniword::Comment?
Resolve a comment (mark it as resolved).
-
#review_queue ⇒ Array<Hash>
Build a combined review queue of comments and revisions, sorted by position (date).
-
#revisions_by_author(author) ⇒ Array<Uniword::Revision>
Get revisions filtered by author.
-
#revisions_by_type(type) ⇒ Array<Uniword::Revision>
Get revisions filtered by type.
Constructor Details
#initialize(document) ⇒ ReviewManager
Initialize a ReviewManager for the given document.
29 30 31 32 |
# File 'lib/uniword/review/review_manager.rb', line 29 def initialize(document) @document = document @accept_reject = AcceptReject.new end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
24 25 26 |
# File 'lib/uniword/review/review_manager.rb', line 24 def document @document end |
Instance Method Details
#accept(revision_id) ⇒ Boolean
Accept a single revision by ID.
142 143 144 145 146 147 148 149 |
# File 'lib/uniword/review/review_manager.rb', line 142 def accept(revision_id) revision = tracked_changes.find_revision(revision_id) return false unless revision @accept_reject.accept(revision) tracked_changes.remove_revision(revision_id) true end |
#accept_all ⇒ Integer
Accept all tracked changes in the document.
167 168 169 |
# File 'lib/uniword/review/review_manager.rb', line 167 def accept_all tracked_changes.accept_all end |
#add_comment(text:, author:, initials: nil) ⇒ Uniword::Comment
Add a new comment to the document.
49 50 51 52 53 54 55 56 |
# File 'lib/uniword/review/review_manager.rb', line 49 def add_comment(text:, author:, initials: nil) comment = Uniword::Comment.new( text: text, author: , initials: initials, ) comments_part.add_comment(comment) end |
#all_authors ⇒ Array<String>
Get all unique authors who have made changes.
182 183 184 185 186 |
# File 'lib/uniword/review/review_manager.rb', line 182 def = comments_part. = tracked_changes. ( + ).uniq.sort end |
#clear_comments ⇒ void
This method returns an undefined value.
Remove all comments from the document.
108 109 110 |
# File 'lib/uniword/review/review_manager.rb', line 108 def clear_comments comments_part.clear end |
#list_comments ⇒ Array<Uniword::Comment>
List all comments in the document.
39 40 41 |
# File 'lib/uniword/review/review_manager.rb', line 39 def list_comments comments_part.comments end |
#list_revisions ⇒ Array<Uniword::Revision>
List all revisions (tracked changes) in the document.
117 118 119 |
# File 'lib/uniword/review/review_manager.rb', line 117 def list_revisions tracked_changes.revisions end |
#reject(revision_id) ⇒ Boolean
Reject a single revision by ID.
155 156 157 158 159 160 161 162 |
# File 'lib/uniword/review/review_manager.rb', line 155 def reject(revision_id) revision = tracked_changes.find_revision(revision_id) return false unless revision @accept_reject.reject(revision) tracked_changes.remove_revision(revision_id) true end |
#reject_all ⇒ Integer
Reject all tracked changes in the document.
174 175 176 |
# File 'lib/uniword/review/review_manager.rb', line 174 def reject_all tracked_changes.reject_all end |
#remove_comment(comment_id) ⇒ Uniword::Comment?
Remove a comment from the document.
101 102 103 |
# File 'lib/uniword/review/review_manager.rb', line 101 def remove_comment(comment_id) comments_part.remove_comment(comment_id) end |
#reply_to_comment(parent_id, text:, author:) ⇒ Uniword::Comment
Reply to an existing comment.
Creates a new comment linked to the parent by convention (same author context).
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/uniword/review/review_manager.rb', line 68 def reply_to_comment(parent_id, text:, author:) parent = comments_part.find_comment(parent_id) unless parent raise ArgumentError, "Comment #{parent_id} not found" end comment = Uniword::Comment.new( text: text, author: , ) comments_part.add_comment(comment) end |
#resolve_comment(comment_id) ⇒ Uniword::Comment?
Resolve a comment (mark it as resolved).
Resolved comments remain in the document but are hidden from the active review interface.
89 90 91 92 93 94 95 |
# File 'lib/uniword/review/review_manager.rb', line 89 def resolve_comment(comment_id) comment = comments_part.find_comment(comment_id) return nil unless comment comment.initials = "#{comment.initials}[resolved]" comment end |
#review_queue ⇒ Array<Hash>
Build a combined review queue of comments and revisions, sorted by position (date).
Each item is a hash with :type (:comment or :revision), :item, and :position keys.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/uniword/review/review_manager.rb', line 195 def review_queue items = comments_part.comments.map do |comment| { type: :comment, item: comment, position: comment.date.to_s, } end tracked_changes.revisions.each do |revision| items << { type: :revision, item: revision, position: revision.date.to_s, } end items.sort_by { |e| e[:position] } end |
#revisions_by_author(author) ⇒ Array<Uniword::Revision>
Get revisions filtered by author.
125 126 127 |
# File 'lib/uniword/review/review_manager.rb', line 125 def () tracked_changes.() end |
#revisions_by_type(type) ⇒ Array<Uniword::Revision>
Get revisions filtered by type.
134 135 136 |
# File 'lib/uniword/review/review_manager.rb', line 134 def revisions_by_type(type) tracked_changes.revisions_by_type(type) end |