Class: Lutaml::Qea::Verification::DocumentNormalizer
- Inherits:
-
Object
- Object
- Lutaml::Qea::Verification::DocumentNormalizer
- Defined in:
- lib/lutaml/qea/verification/document_normalizer.rb
Overview
Normalizes UML documents for comparison by removing XMI IDs, sorting collections, and normalizing strings
Instance Method Summary collapse
-
#normalize(document) ⇒ Lutaml::Uml::Document
Normalize a document for comparison.
-
#normalize_string(text) ⇒ String?
Normalize strings (trim whitespace, normalize case for comparison).
-
#remove_xmi_ids(document) ⇒ void
Remove all XMI IDs from document.
-
#sort_collections(document) ⇒ void
Sort collections in document for consistent comparison.
Instance Method Details
#normalize(document) ⇒ Lutaml::Uml::Document
Normalize a document for comparison
13 14 15 16 17 18 19 |
# File 'lib/lutaml/qea/verification/document_normalizer.rb', line 13 def normalize(document) normalized = deep_copy(document) remove_xmi_ids(normalized) sort_collections(normalized) normalize_strings_in_document(normalized) normalized end |
#normalize_string(text) ⇒ String?
Normalize strings (trim whitespace, normalize case for comparison)
65 66 67 68 69 70 |
# File 'lib/lutaml/qea/verification/document_normalizer.rb', line 65 def normalize_string(text) return nil if text.nil? return text unless text.is_a?(String) text.strip end |
#remove_xmi_ids(document) ⇒ void
This method returns an undefined value.
Remove all XMI IDs from document
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lutaml/qea/verification/document_normalizer.rb', line 25 def remove_xmi_ids(document) # rubocop:disable Metrics/AbcSize # Remove XMI IDs from packages recursively process_packages(document.packages) if document.packages # Remove XMI IDs from classes process_classes(document.classes) if document.classes # Remove XMI IDs from associations process_associations(document.associations) if document.associations # Remove XMI IDs from enums process_enums(document.enums) if document.enums # Remove XMI IDs from data types process_data_types(document.data_types) if document.data_types end |
#sort_collections(document) ⇒ void
This method returns an undefined value.
Sort collections in document for consistent comparison
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/lutaml/qea/verification/document_normalizer.rb', line 46 def sort_collections(document) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity # Sort top-level collections by name document.packages&.sort_by! { |p| p.name || "" } document.classes&.sort_by! { |c| c.name || "" } document.enums&.sort_by! { |e| e.name || "" } document.data_types&.sort_by! { |dt| dt.name || "" } document.associations&.sort_by! do |a| "#{a.owner_end}#{a.member_end}" end # Sort nested collections recursively sort_package_collections(document.packages) if document.packages sort_class_collections(document.classes) if document.classes end |