Class: Uniword::Comment
- Defined in:
- lib/uniword/comment.rb
Overview
Represents a comment in a Word document.
Comments are annotations attached to content ranges, containing author information, timestamp, and comment text. They are part of Word’s review and collaboration features.
In OOXML, comments are stored in word/comments.xml and referenced via commentRangeStart, commentRangeEnd, and commentReference elements.
Instance Attribute Summary collapse
-
#author ⇒ String
Comment author name.
-
#comment_id ⇒ Integer
Unique comment identifier.
-
#date ⇒ Time
Comment creation date/time.
-
#initials ⇒ String
Author initials (optional).
-
#text ⇒ String
Get the plain text content of this comment Concatenates text from all paragraphs.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
Accept a visitor for the visitor pattern.
-
#empty? ⇒ Boolean
Check if comment is empty (has no paragraphs or all paragraphs are empty).
-
#initialize(attributes = {}) ⇒ Comment
constructor
Initialize a new comment.
-
#inspect ⇒ String
Provide detailed inspection for debugging.
-
#valid? ⇒ Boolean
Check if comment is valid (has required attributes).
Methods inherited from Element
Constructor Details
#initialize(attributes = {}) ⇒ Comment
Initialize a new comment
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/uniword/comment.rb', line 59 def initialize(attributes = {}) # Extract text before calling super to handle it specially text_content = attributes.delete(:text) super # Auto-generate comment_id if not provided @comment_id ||= generate_comment_id # Set date to current time if not provided @date ||= format_date(Time.now) # Add text as a paragraph if provided return unless text_content && !text_content.empty? para = Uniword::Wordprocessingml::Paragraph.new run = Uniword::Wordprocessingml::Run.new(text: text_content) para.runs << run paragraphs << para end |
Instance Attribute Details
#author ⇒ String
Comment author name
21 22 23 |
# File 'lib/uniword/comment.rb', line 21 def @author end |
#comment_id ⇒ Integer
Unique comment identifier
21 22 23 |
# File 'lib/uniword/comment.rb', line 21 def comment_id @comment_id end |
#date ⇒ Time
Comment creation date/time
21 22 23 |
# File 'lib/uniword/comment.rb', line 21 def date @date end |
#initials ⇒ String
Author initials (optional)
21 22 23 |
# File 'lib/uniword/comment.rb', line 21 def initials @initials end |
#text ⇒ String
Get the plain text content of this comment Concatenates text from all paragraphs
21 22 23 |
# File 'lib/uniword/comment.rb', line 21 def text @text end |
Instance Method Details
#accept(visitor) ⇒ Object
Accept a visitor for the visitor pattern
84 85 86 |
# File 'lib/uniword/comment.rb', line 84 def accept(visitor) visitor.visit_comment(self) end |
#empty? ⇒ Boolean
Check if comment is empty (has no paragraphs or all paragraphs are empty)
99 100 101 |
# File 'lib/uniword/comment.rb', line 99 def empty? paragraphs.empty? || paragraphs.all?(&:empty?) end |
#inspect ⇒ String
Provide detailed inspection for debugging
106 107 108 109 110 |
# File 'lib/uniword/comment.rb', line 106 def inspect text_preview = text[0..50] text_preview += "..." if text.length > 50 "#<Uniword::Comment id=#{comment_id.inspect} author=#{.inspect} text=#{text_preview.inspect}>" end |
#valid? ⇒ Boolean
Check if comment is valid (has required attributes)
115 116 117 |
# File 'lib/uniword/comment.rb', line 115 def valid? required_attributes_valid? end |