Class: Uniword::CommentsPart
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::CommentsPart
- Defined in:
- lib/uniword/comments_part.rb
Overview
Represents the comments part of a Word document (word/comments.xml).
This class manages the collection of all comments in a document. In OOXML packages, comments are stored separately from the main document in word/comments.xml.
The CommentsPart maintains a collection of Comment objects and handles serialization/deserialization to/from the comments.xml file.
Instance Attribute Summary collapse
-
#comments ⇒ Array<Comment>
Collection of all comments.
Instance Method Summary collapse
-
#add_comment(comment) ⇒ Comment
Add a comment to the collection.
-
#authors ⇒ Array<String>
Get all unique authors.
-
#clear ⇒ void
Clear all comments.
-
#comments_by_author(author) ⇒ Array<Comment>
Get all comments by a specific author.
-
#count ⇒ Integer
Get the number of comments.
-
#empty? ⇒ Boolean
Check if there are any comments.
-
#find_comment(comment_id) ⇒ Comment?
Find a comment by ID.
-
#initialize(attributes = {}) ⇒ CommentsPart
constructor
Initialize a new comments part.
-
#inspect ⇒ String
Provide detailed inspection for debugging.
-
#remove_comment(comment_id) ⇒ Comment?
Remove a comment by ID.
Constructor Details
#initialize(attributes = {}) ⇒ CommentsPart
Initialize a new comments part
39 40 41 42 |
# File 'lib/uniword/comments_part.rb', line 39 def initialize(attributes = {}) super @comment_counter = 0 end |
Instance Attribute Details
#comments ⇒ Array<Comment>
Collection of all comments
24 25 26 |
# File 'lib/uniword/comments_part.rb', line 24 def comments @comments end |
Instance Method Details
#add_comment(comment) ⇒ Comment
Add a comment to the collection
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/uniword/comments_part.rb', line 48 def add_comment(comment) unless comment.is_a?(Comment) raise ArgumentError, "comment must be a Comment instance" end # Assign sequential ID if not already set comment.comment_id = next_comment_id unless comment.comment_id && !comment.comment_id.empty? comments << comment comment end |
#authors ⇒ Array<String>
Get all unique authors
104 105 106 |
# File 'lib/uniword/comments_part.rb', line 104 def comments.map(&:author).uniq.compact end |
#clear ⇒ void
This method returns an undefined value.
Clear all comments
111 112 113 114 |
# File 'lib/uniword/comments_part.rb', line 111 def clear comments.clear @comment_counter = 0 end |
#comments_by_author(author) ⇒ Array<Comment>
Get all comments by a specific author
83 84 85 |
# File 'lib/uniword/comments_part.rb', line 83 def () comments.select { |c| c. == } end |
#count ⇒ Integer
Get the number of comments
90 91 92 |
# File 'lib/uniword/comments_part.rb', line 90 def count comments.size end |
#empty? ⇒ Boolean
Check if there are any comments
97 98 99 |
# File 'lib/uniword/comments_part.rb', line 97 def empty? comments.empty? end |
#find_comment(comment_id) ⇒ Comment?
Find a comment by ID
65 66 67 |
# File 'lib/uniword/comments_part.rb', line 65 def find_comment(comment_id) comments.find { |c| c.comment_id == comment_id.to_s } end |
#inspect ⇒ String
Provide detailed inspection for debugging
119 120 121 |
# File 'lib/uniword/comments_part.rb', line 119 def inspect "#<Uniword::CommentsPart count=#{count} authors=#{.count}>" end |
#remove_comment(comment_id) ⇒ Comment?
Remove a comment by ID
73 74 75 76 77 |
# File 'lib/uniword/comments_part.rb', line 73 def remove_comment(comment_id) comment = find_comment(comment_id) comments.delete(comment) if comment comment end |