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.
140 141 142 143 144 145 146 147 |
# File 'lib/uniword/review/review_manager.rb', line 140 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.
165 166 167 |
# File 'lib/uniword/review/review_manager.rb', line 165 def accept_all tracked_changes.accept_all end |
#add_comment(text:, author:, initials: nil) ⇒ Uniword::Comment
Add a new comment to the document.
47 48 49 50 51 52 53 54 |
# File 'lib/uniword/review/review_manager.rb', line 47 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.
180 181 182 183 184 |
# File 'lib/uniword/review/review_manager.rb', line 180 def = comments_part. = tracked_changes. ( + ).uniq.sort end |
#clear_comments ⇒ void
This method returns an undefined value.
Remove all comments from the document.
106 107 108 |
# File 'lib/uniword/review/review_manager.rb', line 106 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.
115 116 117 |
# File 'lib/uniword/review/review_manager.rb', line 115 def list_revisions tracked_changes.revisions end |
#reject(revision_id) ⇒ Boolean
Reject a single revision by ID.
153 154 155 156 157 158 159 160 |
# File 'lib/uniword/review/review_manager.rb', line 153 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.
172 173 174 |
# File 'lib/uniword/review/review_manager.rb', line 172 def reject_all tracked_changes.reject_all end |
#remove_comment(comment_id) ⇒ Uniword::Comment?
Remove a comment from the document.
99 100 101 |
# File 'lib/uniword/review/review_manager.rb', line 99 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).
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/uniword/review/review_manager.rb', line 66 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.
87 88 89 90 91 92 93 |
# File 'lib/uniword/review/review_manager.rb', line 87 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.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/uniword/review/review_manager.rb', line 193 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.
123 124 125 |
# File 'lib/uniword/review/review_manager.rb', line 123 def () tracked_changes.() end |
#revisions_by_type(type) ⇒ Array<Uniword::Revision>
Get revisions filtered by type.
132 133 134 |
# File 'lib/uniword/review/review_manager.rb', line 132 def revisions_by_type(type) tracked_changes.revisions_by_type(type) end |