Class: Uniword::Review::ReviewManager

Inherits:
Object
  • Object
show all
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.

Examples:

List all comments

manager = ReviewManager.new(doc)
manager.list_comments

Accept all tracked changes

manager.accept_all

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ ReviewManager

Initialize a ReviewManager for the given document.

Parameters:



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

#documentObject (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.

Parameters:

  • revision_id (String)

    The revision ID to accept

Returns:

  • (Boolean)

    true if accepted, false if not found



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_allInteger

Accept all tracked changes in the document.

Returns:

  • (Integer)

    Number of changes accepted



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.

Parameters:

  • text (String)

    Comment text

  • author (String)

    Author name

  • initials (String, nil) (defaults to: nil)

    Author initials

Returns:



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: author,
    initials: initials,
  )
  comments_part.add_comment(comment)
end

#all_authorsArray<String>

Get all unique authors who have made changes.

Returns:

  • (Array<String>)

    Unique author names from both comments and revisions



180
181
182
183
184
# File 'lib/uniword/review/review_manager.rb', line 180

def all_authors
  comment_authors = comments_part.authors
  revision_authors = tracked_changes.authors
  (comment_authors + revision_authors).uniq.sort
end

#clear_commentsvoid

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_commentsArray<Uniword::Comment>

List all comments in the document.

Returns:



37
38
39
# File 'lib/uniword/review/review_manager.rb', line 37

def list_comments
  comments_part.comments
end

#list_revisionsArray<Uniword::Revision>

List all revisions (tracked changes) in the document.

Returns:



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.

Parameters:

  • revision_id (String)

    The revision ID to reject

Returns:

  • (Boolean)

    true if rejected, false if not found



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_allInteger

Reject all tracked changes in the document.

Returns:

  • (Integer)

    Number of changes rejected



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.

Parameters:

  • comment_id (String)

    The comment ID to remove

Returns:



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).

Parameters:

  • parent_id (String)

    The parent comment ID

  • text (String)

    Reply text

  • author (String)

    Author name

Returns:

Raises:

  • (ArgumentError)

    If parent comment not found



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: 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.

Parameters:

  • comment_id (String)

    The comment ID to resolve

Returns:



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_queueArray<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.

Returns:

  • (Array<Hash>)

    Combined review queue



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.

Parameters:

  • author (String)

    Author name

Returns:



123
124
125
# File 'lib/uniword/review/review_manager.rb', line 123

def revisions_by_author(author)
  tracked_changes.revisions_by_author(author)
end

#revisions_by_type(type) ⇒ Array<Uniword::Revision>

Get revisions filtered by type.

Parameters:

  • type (Symbol)

    Revision type (:insert, :delete, :format_change)

Returns:



132
133
134
# File 'lib/uniword/review/review_manager.rb', line 132

def revisions_by_type(type)
  tracked_changes.revisions_by_type(type)
end