Class: Uniword::Diff::DiffResult
- Inherits:
-
Object
- Object
- Uniword::Diff::DiffResult
- Defined in:
- lib/uniword/diff/diff_result.rb
Overview
Value object holding the result of comparing two documents.
Contains arrays of text, formatting, structural, metadata, and style changes discovered during a diff operation. Use #empty? to check if the two documents are identical.
Instance Attribute Summary collapse
-
#format_changes ⇒ Object
readonly
Returns the value of attribute format_changes.
-
#metadata_changes ⇒ Object
readonly
Returns the value of attribute metadata_changes.
-
#structure_changes ⇒ Object
readonly
Returns the value of attribute structure_changes.
-
#style_changes ⇒ Object
readonly
Returns the value of attribute style_changes.
-
#text_changes ⇒ Object
readonly
Returns the value of attribute text_changes.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Whether the documents are identical (no changes of any kind).
-
#initialize(text_changes: [], format_changes: [], structure_changes: [], metadata_changes: {}, style_changes: []) ⇒ DiffResult
constructor
Initialize a DiffResult with change arrays.
-
#summary ⇒ String
Human-readable summary of changes.
-
#to_h ⇒ Hash
Convert to a plain Hash suitable for serialization.
-
#to_json(*_args) ⇒ String
Serialize to JSON string.
-
#total_changes ⇒ Integer
Total number of changes across all categories.
Constructor Details
#initialize(text_changes: [], format_changes: [], structure_changes: [], metadata_changes: {}, style_changes: []) ⇒ DiffResult
Initialize a DiffResult with change arrays.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/uniword/diff/diff_result.rb', line 29 def initialize(text_changes: [], format_changes: [], structure_changes: [], metadata_changes: {}, style_changes: []) @text_changes = text_changes @format_changes = format_changes @structure_changes = structure_changes @metadata_changes = @style_changes = style_changes end |
Instance Attribute Details
#format_changes ⇒ Object (readonly)
Returns the value of attribute format_changes.
18 19 20 |
# File 'lib/uniword/diff/diff_result.rb', line 18 def format_changes @format_changes end |
#metadata_changes ⇒ Object (readonly)
Returns the value of attribute metadata_changes.
18 19 20 |
# File 'lib/uniword/diff/diff_result.rb', line 18 def @metadata_changes end |
#structure_changes ⇒ Object (readonly)
Returns the value of attribute structure_changes.
18 19 20 |
# File 'lib/uniword/diff/diff_result.rb', line 18 def structure_changes @structure_changes end |
#style_changes ⇒ Object (readonly)
Returns the value of attribute style_changes.
18 19 20 |
# File 'lib/uniword/diff/diff_result.rb', line 18 def style_changes @style_changes end |
#text_changes ⇒ Object (readonly)
Returns the value of attribute text_changes.
18 19 20 |
# File 'lib/uniword/diff/diff_result.rb', line 18 def text_changes @text_changes end |
Instance Method Details
#empty? ⇒ Boolean
Whether the documents are identical (no changes of any kind).
44 45 46 47 48 49 50 |
# File 'lib/uniword/diff/diff_result.rb', line 44 def empty? text_changes.empty? && format_changes.empty? && structure_changes.empty? && .empty? && style_changes.empty? end |
#summary ⇒ String
Human-readable summary of changes.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/uniword/diff/diff_result.rb', line 66 def summary return "No differences found." if empty? parts = [] parts << "#{text_changes.size} text change(s)" if text_changes.any? parts << "#{format_changes.size} format change(s)" if format_changes.any? parts << "#{structure_changes.size} structural change(s)" if structure_changes.any? parts << "#{.size} metadata change(s)" if .any? parts << "#{style_changes.size} style change(s)" if style_changes.any? parts.join(", ") end |
#to_h ⇒ Hash
Convert to a plain Hash suitable for serialization.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/uniword/diff/diff_result.rb', line 88 def to_h { text_changes: text_changes, format_changes: format_changes, structure_changes: structure_changes, metadata_changes: , style_changes: style_changes, summary: summary, } end |
#to_json(*_args) ⇒ String
Serialize to JSON string.
81 82 83 |
# File 'lib/uniword/diff/diff_result.rb', line 81 def to_json(*_args) JSON.pretty_generate(to_h) end |
#total_changes ⇒ Integer
Total number of changes across all categories.
55 56 57 58 59 60 61 |
# File 'lib/uniword/diff/diff_result.rb', line 55 def total_changes text_changes.size + format_changes.size + structure_changes.size + .size + style_changes.size end |