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.
27 28 29 30 |
# File 'lib/uniword/review/review_manager.rb', line 27 def initialize(document) @document = document @accept_reject = AcceptReject.new end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
22 23 24 |
# File 'lib/uniword/review/review_manager.rb', line 22 def document @document end |
Instance Method Details
#accept(revision_id) ⇒ Boolean
Accept a single revision by ID.
146 147 148 149 150 151 152 153 |
# File 'lib/uniword/review/review_manager.rb', line 146 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.
171 172 173 |
# File 'lib/uniword/review/review_manager.rb', line 171 def accept_all tracked_changes.accept_all end |
#add_comment(text:, author:, initials: nil) ⇒ Uniword::Comment
Add a new comment to the document.
The comment is registered in the document's CommentsPart, which the save path serializes to word/comments.xml. The collection assigns a sequential decimal ID (OOXML ST_DecimalNumber).
51 52 53 54 55 56 57 58 59 |
# File 'lib/uniword/review/review_manager.rb', line 51 def add_comment(text:, author:, initials: nil) comment = Uniword::Comment.new( text: text, author: , initials: initials, ) comment.comment_id = nil comments_part.add_comment(comment) end |
#all_authors ⇒ Array<String>
Get all unique authors who have made changes.
186 187 188 189 190 |
# File 'lib/uniword/review/review_manager.rb', line 186 def = comments_part. = tracked_changes. ( + ).uniq.sort end |
#clear_comments ⇒ void
This method returns an undefined value.
Remove all comments from the document.
112 113 114 |
# File 'lib/uniword/review/review_manager.rb', line 112 def clear_comments comments_part.clear end |
#list_comments ⇒ Array<Uniword::Comment>
List all comments in the document.
37 38 39 |
# File 'lib/uniword/review/review_manager.rb', line 37 def list_comments comments_part.comments end |
#list_revisions ⇒ Array<Uniword::Revision>
List all revisions (tracked changes) in the document.
121 122 123 |
# File 'lib/uniword/review/review_manager.rb', line 121 def list_revisions tracked_changes.revisions end |
#reject(revision_id) ⇒ Boolean
Reject a single revision by ID.
159 160 161 162 163 164 165 166 |
# File 'lib/uniword/review/review_manager.rb', line 159 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.
178 179 180 |
# File 'lib/uniword/review/review_manager.rb', line 178 def reject_all tracked_changes.reject_all end |
#remove_comment(comment_id) ⇒ Uniword::Comment?
Remove a comment from the document.
105 106 107 |
# File 'lib/uniword/review/review_manager.rb', line 105 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).
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/uniword/review/review_manager.rb', line 71 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: , ) comment.comment_id = nil 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.
93 94 95 96 97 98 99 |
# File 'lib/uniword/review/review_manager.rb', line 93 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.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/uniword/review/review_manager.rb', line 199 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.
129 130 131 |
# File 'lib/uniword/review/review_manager.rb', line 129 def () tracked_changes.() end |
#revisions_by_type(type) ⇒ Array<Uniword::Revision>
Get revisions filtered by type.
138 139 140 |
# File 'lib/uniword/review/review_manager.rb', line 138 def revisions_by_type(type) tracked_changes.revisions_by_type(type) end |