Class: Uniword::Diff::DocumentDiffer

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/diff/document_differ.rb

Overview

Compares two DocumentRoot instances and produces a DiffResult.

Uses LCS (longest common subsequence) alignment for paragraphs to detect added, removed, and modified paragraphs. Optionally compares formatting, structure, metadata, and styles.

Examples:

old_doc = DocumentFactory.from_file("v1.docx")
new_doc = DocumentFactory.from_file("v2.docx")
result = DocumentDiffer.new(old_doc, new_doc).diff
puts result.summary

Instance Method Summary collapse

Constructor Details

#initialize(old_doc, new_doc, options: {}) ⇒ DocumentDiffer

Initialize with two documents and options.

Parameters:

Options Hash (options:):

  • :text_only (Boolean)

    Skip formatting comparison

  • :part (String)

    Focus on a specific part (styles/headers/content)



27
28
29
30
31
# File 'lib/uniword/diff/document_differ.rb', line 27

def initialize(old_doc, new_doc, options: {})
  @old_doc = old_doc
  @new_doc = new_doc
  @options = options
end

Instance Method Details

#diffDiffResult

Perform the diff and return a DiffResult.

Returns:



36
37
38
39
40
41
42
43
44
# File 'lib/uniword/diff/document_differ.rb', line 36

def diff
  DiffResult.new(
    text_changes: diff_text,
    format_changes: text_only? ? [] : diff_formatting,
    structure_changes: diff_structure,
    metadata_changes: ,
    style_changes: diff_styles,
  )
end