Class: Uniword::Diff::PackageDiffResult
- Inherits:
-
Object
- Object
- Uniword::Diff::PackageDiffResult
- Defined in:
- lib/uniword/diff/package_diff_result.rb
Overview
Value object holding the result of comparing two DOCX packages.
Contains lists of added, removed, and modified ZIP parts, plus detailed XML change descriptions for modified parts, ZIP metadata differences, and OPC validation issues.
Instance Attribute Summary collapse
-
#added_parts ⇒ Object
readonly
Returns the value of attribute added_parts.
-
#modified_parts ⇒ Object
readonly
Returns the value of attribute modified_parts.
-
#new_path ⇒ Object
readonly
Returns the value of attribute new_path.
-
#old_path ⇒ Object
readonly
Returns the value of attribute old_path.
-
#opc_issues ⇒ Object
readonly
Returns the value of attribute opc_issues.
-
#removed_parts ⇒ Object
readonly
Returns the value of attribute removed_parts.
-
#unchanged_parts ⇒ Object
readonly
Returns the value of attribute unchanged_parts.
-
#xml_changes ⇒ Object
readonly
Returns the value of attribute xml_changes.
-
#zip_metadata_changes ⇒ Object
readonly
Returns the value of attribute zip_metadata_changes.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Whether the two packages are identical.
-
#initialize(old_path:, new_path:, added_parts:, removed_parts:, modified_parts:, unchanged_parts:, xml_changes:, zip_metadata_changes: [], opc_issues: []) ⇒ PackageDiffResult
constructor
Initialize a PackageDiffResult.
-
#summary ⇒ String
Human-readable summary.
-
#to_h ⇒ Hash
Convert to plain Hash.
-
#to_json(*_args) ⇒ String
Serialize to JSON string.
-
#total_changes ⇒ Integer
Total number of changes.
Constructor Details
#initialize(old_path:, new_path:, added_parts:, removed_parts:, modified_parts:, unchanged_parts:, xml_changes:, zip_metadata_changes: [], opc_issues: []) ⇒ PackageDiffResult
Initialize a PackageDiffResult.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/uniword/diff/package_diff_result.rb', line 130 def initialize(old_path:, new_path:, added_parts:, removed_parts:, modified_parts:, unchanged_parts:, xml_changes:, zip_metadata_changes: [], opc_issues: []) @old_path = old_path @new_path = new_path @added_parts = added_parts @removed_parts = removed_parts @modified_parts = modified_parts @unchanged_parts = unchanged_parts @xml_changes = xml_changes @zip_metadata_changes = @opc_issues = opc_issues end |
Instance Attribute Details
#added_parts ⇒ Object (readonly)
Returns the value of attribute added_parts.
113 114 115 |
# File 'lib/uniword/diff/package_diff_result.rb', line 113 def added_parts @added_parts end |
#modified_parts ⇒ Object (readonly)
Returns the value of attribute modified_parts.
113 114 115 |
# File 'lib/uniword/diff/package_diff_result.rb', line 113 def modified_parts @modified_parts end |
#new_path ⇒ Object (readonly)
Returns the value of attribute new_path.
113 114 115 |
# File 'lib/uniword/diff/package_diff_result.rb', line 113 def new_path @new_path end |
#old_path ⇒ Object (readonly)
Returns the value of attribute old_path.
113 114 115 |
# File 'lib/uniword/diff/package_diff_result.rb', line 113 def old_path @old_path end |
#opc_issues ⇒ Object (readonly)
Returns the value of attribute opc_issues.
113 114 115 |
# File 'lib/uniword/diff/package_diff_result.rb', line 113 def opc_issues @opc_issues end |
#removed_parts ⇒ Object (readonly)
Returns the value of attribute removed_parts.
113 114 115 |
# File 'lib/uniword/diff/package_diff_result.rb', line 113 def removed_parts @removed_parts end |
#unchanged_parts ⇒ Object (readonly)
Returns the value of attribute unchanged_parts.
113 114 115 |
# File 'lib/uniword/diff/package_diff_result.rb', line 113 def unchanged_parts @unchanged_parts end |
#xml_changes ⇒ Object (readonly)
Returns the value of attribute xml_changes.
113 114 115 |
# File 'lib/uniword/diff/package_diff_result.rb', line 113 def xml_changes @xml_changes end |
#zip_metadata_changes ⇒ Object (readonly)
Returns the value of attribute zip_metadata_changes.
113 114 115 |
# File 'lib/uniword/diff/package_diff_result.rb', line 113 def @zip_metadata_changes end |
Instance Method Details
#empty? ⇒ Boolean
Whether the two packages are identical.
149 150 151 152 |
# File 'lib/uniword/diff/package_diff_result.rb', line 149 def empty? added_parts.empty? && removed_parts.empty? && modified_parts.empty? end |
#summary ⇒ String
Human-readable summary.
164 165 166 167 168 169 170 171 172 |
# File 'lib/uniword/diff/package_diff_result.rb', line 164 def summary return "No differences found." if empty? parts = [] parts << "#{added_parts.size} part(s) added" if added_parts.any? parts << "#{removed_parts.size} part(s) removed" if removed_parts.any? parts << "#{modified_parts.size} part(s) modified" if modified_parts.any? parts.join(", ") end |
#to_h ⇒ Hash
Convert to plain Hash.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/uniword/diff/package_diff_result.rb', line 184 def to_h h = { old_path: @old_path, new_path: @new_path, summary: summary, added_parts: @added_parts, removed_parts: @removed_parts, modified_parts: @modified_parts.map(&:to_h), unchanged_count: @unchanged_parts.size, xml_changes: @xml_changes.map(&:to_h), } if @zip_metadata_changes.any? h[:zip_metadata_changes] = @zip_metadata_changes.map(&:to_h) end h[:opc_issues] = @opc_issues.map(&:to_h) if @opc_issues.any? h end |
#to_json(*_args) ⇒ String
Serialize to JSON string.
177 178 179 |
# File 'lib/uniword/diff/package_diff_result.rb', line 177 def to_json(*_args) JSON.pretty_generate(to_h) end |
#total_changes ⇒ Integer
Total number of changes.
157 158 159 |
# File 'lib/uniword/diff/package_diff_result.rb', line 157 def total_changes added_parts.size + removed_parts.size + modified_parts.size end |