Class: Uniword::Revision
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::Revision
- Defined in:
- lib/uniword/revision.rb
Overview
Represents a single revision (change) in a Word document.
Revisions are part of Word’s track changes feature, recording insertions, deletions, and formatting changes with author and timestamp information.
In OOXML:
-
Insertions: <w:ins>
-
Deletions: <w:del>
-
Format changes: <w:rPrChange>, <w:pPrChange>
Instance Attribute Summary collapse
-
#author ⇒ String
Author name.
-
#content ⇒ Object
Content affected by revision.
-
#date ⇒ String
Revision date/time.
-
#revision_id ⇒ String
Unique revision identifier.
-
#text ⇒ String
Get text content.
-
#type ⇒ Object
Revision type (:insert, :delete, :format_change).
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
Accept a visitor for the visitor pattern.
-
#delete? ⇒ Boolean
Check if this is a deletion.
-
#format_change? ⇒ Boolean
Check if this is a format change.
-
#initialize(attributes = {}) ⇒ Revision
constructor
Initialize a new revision.
-
#insert? ⇒ Boolean
Check if this is an insertion.
-
#inspect ⇒ String
Provide detailed inspection for debugging.
-
#valid? ⇒ Boolean
Check if this revision is valid.
-
#xml_element_name ⇒ String
Get the XML element name based on revision type.
Constructor Details
#initialize(attributes = {}) ⇒ Revision
Initialize a new revision
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/uniword/revision.rb', line 70 def initialize(attributes = {}) # Extract custom attributes before calling super @type = attributes.delete(:type) || :insert text_content = attributes.delete(:text) @content = attributes.delete(:content) super # Auto-generate revision_id if not provided @revision_id ||= generate_revision_id # Set date to current time if not provided @date ||= format_date(Time.now) # Set content from text if provided return unless text_content && !text_content.empty? @content = text_content end |
Instance Attribute Details
#author ⇒ String
Author name
36 37 38 |
# File 'lib/uniword/revision.rb', line 36 def @author end |
#content ⇒ Object
Content affected by revision
60 61 62 |
# File 'lib/uniword/revision.rb', line 60 def content @content end |
#date ⇒ String
Revision date/time
36 37 38 |
# File 'lib/uniword/revision.rb', line 36 def date @date end |
#revision_id ⇒ String
Unique revision identifier
36 37 38 |
# File 'lib/uniword/revision.rb', line 36 def revision_id @revision_id end |
#text ⇒ String
Get text content
36 37 38 |
# File 'lib/uniword/revision.rb', line 36 def text @text end |
#type ⇒ Object
Revision type (:insert, :delete, :format_change)
36 37 38 |
# File 'lib/uniword/revision.rb', line 36 def type @type end |
Instance Method Details
#accept(visitor) ⇒ Object
Accept a visitor for the visitor pattern
94 95 96 |
# File 'lib/uniword/revision.rb', line 94 def accept(visitor) visitor.visit_revision(self) end |
#delete? ⇒ Boolean
Check if this is a deletion
115 116 117 |
# File 'lib/uniword/revision.rb', line 115 def delete? type == :delete end |
#format_change? ⇒ Boolean
Check if this is a format change
122 123 124 |
# File 'lib/uniword/revision.rb', line 122 def format_change? type == :format_change end |
#insert? ⇒ Boolean
Check if this is an insertion
108 109 110 |
# File 'lib/uniword/revision.rb', line 108 def insert? type == :insert end |
#inspect ⇒ String
Provide detailed inspection for debugging
155 156 157 158 159 |
# File 'lib/uniword/revision.rb', line 155 def inspect text_preview = text[0..30] text_preview += "..." if text.length > 30 "#<Uniword::Revision type=#{type.inspect} author=#{.inspect} text=#{text_preview.inspect}>" end |
#valid? ⇒ Boolean
Check if this revision is valid
A revision is valid if it has a non-empty author, a revision_id, a type, and the type is one of the valid types.
132 133 134 |
# File 'lib/uniword/revision.rb', line 132 def valid? required_attributes_valid? end |
#xml_element_name ⇒ String
Get the XML element name based on revision type
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/uniword/revision.rb', line 139 def xml_element_name case type when :insert "ins" when :delete "del" when :format_change "rPrChange" else raise ArgumentError, "Invalid revision type: #{type}" end end |