Class: Uniword::CommentsPart
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::CommentsPart
- Includes:
- Enumerable
- 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
-
#[](index) ⇒ Comment?
Array-style access to comments (Array compatibility).
-
#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.
-
#each {|Comment| ... } ⇒ Enumerator, Array<Comment>
Iterate over the comments (Array compatibility).
-
#empty? ⇒ Boolean
Check if there are any comments.
-
#find_comment(comment_id) ⇒ Comment?
Find a comment by ID.
-
#inspect ⇒ String
Provide detailed inspection for debugging.
-
#remove_comment(comment_id) ⇒ Comment?
Remove a comment by ID.
-
#size ⇒ Integer
Get the number of comments (Array compatibility).
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
#[](index) ⇒ Comment?
Array-style access to comments (Array compatibility)
109 110 111 |
# File 'lib/uniword/comments_part.rb', line 109 def [](index) comments[index] end |
#add_comment(comment) ⇒ Comment
Add a comment to the collection
Assigns the next sequential decimal ID when the comment has no ID yet or its ID collides with one already in the collection; explicit unique IDs are preserved.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/uniword/comments_part.rb', line 46 def add_comment(comment) unless comment.is_a?(Comment) raise ArgumentError, "comment must be a Comment instance" end comment.comment_id = next_comment_id if assign_id?(comment) comments << comment comment end |
#authors ⇒ Array<String>
Get all unique authors
123 124 125 |
# File 'lib/uniword/comments_part.rb', line 123 def comments.map(&:author).uniq.compact end |
#clear ⇒ void
This method returns an undefined value.
Clear all comments
130 131 132 |
# File 'lib/uniword/comments_part.rb', line 130 def clear comments.clear end |
#comments_by_author(author) ⇒ Array<Comment>
Get all comments by a specific author
79 80 81 |
# File 'lib/uniword/comments_part.rb', line 79 def () comments.select { |c| c. == } end |
#count ⇒ Integer
Get the number of comments
86 87 88 |
# File 'lib/uniword/comments_part.rb', line 86 def count comments.size end |
#each {|Comment| ... } ⇒ Enumerator, Array<Comment>
Iterate over the comments (Array compatibility)
101 102 103 |
# File 'lib/uniword/comments_part.rb', line 101 def each(&block) comments.each(&block) end |
#empty? ⇒ Boolean
Check if there are any comments
116 117 118 |
# File 'lib/uniword/comments_part.rb', line 116 def empty? comments.empty? end |
#find_comment(comment_id) ⇒ Comment?
Find a comment by ID
61 62 63 |
# File 'lib/uniword/comments_part.rb', line 61 def find_comment(comment_id) comments.find { |c| c.comment_id == comment_id.to_s } end |
#inspect ⇒ String
Provide detailed inspection for debugging
137 138 139 |
# File 'lib/uniword/comments_part.rb', line 137 def inspect "#<Uniword::CommentsPart count=#{count} authors=#{.count}>" end |
#remove_comment(comment_id) ⇒ Comment?
Remove a comment by ID
69 70 71 72 73 |
# File 'lib/uniword/comments_part.rb', line 69 def remove_comment(comment_id) comment = find_comment(comment_id) comments.delete(comment) if comment comment end |
#size ⇒ Integer
Get the number of comments (Array compatibility)
93 94 95 |
# File 'lib/uniword/comments_part.rb', line 93 def size comments.size end |