Class: Uniword::Revision

Inherits:
Lutaml::Model::Serializable
  • Object
show all
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>

Examples:

Create an insertion

revision = Uniword::Revision.new(
  type: :insert,
  author: "John Doe",
  text: "New text"
)

Create a deletion

revision = Uniword::Revision.new(
  type: :delete,
  author: "Jane Smith",
  text: "Deleted text"
)

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Revision

Initialize a new revision

Parameters:

  • attributes (Hash) (defaults to: {})

    Revision attributes

Options Hash (attributes):

  • :type (Symbol)

    Revision type

  • :author (String)

    Author name

  • :text (String)

    Text content

  • :date (String)

    Revision date

  • :revision_id (String)

    Unique ID



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

#authorString

Author name

Returns:

  • (String)

    the current value of author



36
37
38
# File 'lib/uniword/revision.rb', line 36

def author
  @author
end

#contentObject

Content affected by revision



60
61
62
# File 'lib/uniword/revision.rb', line 60

def content
  @content
end

#dateString

Revision date/time

Returns:

  • (String)

    the current value of date



36
37
38
# File 'lib/uniword/revision.rb', line 36

def date
  @date
end

#revision_idString

Unique revision identifier

Returns:

  • (String)

    the current value of revision_id



36
37
38
# File 'lib/uniword/revision.rb', line 36

def revision_id
  @revision_id
end

#textString

Get text content

Returns:

  • (String)

    The text content



36
37
38
# File 'lib/uniword/revision.rb', line 36

def text
  @text
end

#typeObject

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

Parameters:

  • visitor (Object)

    The visitor object

Returns:

  • (Object)

    The result of the visit operation



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

Returns:

  • (Boolean)

    true if 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

Returns:

  • (Boolean)

    true if 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

Returns:

  • (Boolean)

    true if insertion



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

def insert?
  type == :insert
end

#inspectString

Provide detailed inspection for debugging

Returns:

  • (String)

    A readable representation of the revision



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=#{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.

Returns:

  • (Boolean)

    true if valid



132
133
134
# File 'lib/uniword/revision.rb', line 132

def valid?
  required_attributes_valid?
end

#xml_element_nameString

Get the XML element name based on revision type

Returns:

  • (String)

    The XML element name



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