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:



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

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

Parameters:

  • revision_id (String)

    The revision ID to accept

Returns:

  • (Boolean)

    true if accepted, false if not found



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_allInteger

Accept all tracked changes in the document.

Returns:

  • (Integer)

    Number of changes accepted



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.

Parameters:

  • text (String)

    Comment text

  • author (String)

    Author name

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

    Author initials

Returns:



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



182
183
184
185
186
# File 'lib/uniword/review/review_manager.rb', line 182

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.



108
109
110
# File 'lib/uniword/review/review_manager.rb', line 108

def clear_comments
  comments_part.clear
end

#list_commentsArray<Uniword::Comment>

List all comments in the document.

Returns:



39
40
41
# File 'lib/uniword/review/review_manager.rb', line 39

def list_comments
  comments_part.comments
end

#list_revisionsArray<Uniword::Revision>

List all revisions (tracked changes) in the document.

Returns:



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.

Parameters:

  • revision_id (String)

    The revision ID to reject

Returns:

  • (Boolean)

    true if rejected, false if not found



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_allInteger

Reject all tracked changes in the document.

Returns:

  • (Integer)

    Number of changes rejected



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.

Parameters:

  • comment_id (String)

    The comment ID to remove

Returns:



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

Parameters:

  • parent_id (String)

    The parent comment ID

  • text (String)

    Reply text

  • author (String)

    Author name

Returns:

Raises:

  • (ArgumentError)

    If parent comment not found



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



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_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



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.

Parameters:

  • author (String)

    Author name

Returns:



125
126
127
# File 'lib/uniword/review/review_manager.rb', line 125

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:



134
135
136
# File 'lib/uniword/review/review_manager.rb', line 134

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