Module: Lutaml::Model::ComparableModel::ClassMethods
- Included in:
- Serializable
- Defined in:
- lib/lutaml/model/comparable_model.rb
Overview
Class methods added to the class that includes ComparableModel
Instance Method Summary collapse
-
#diff_tree ⇒ String
Generates a diff tree between two objects of the same class.
-
#diff_with_score(obj1, obj2, **options) ⇒ Array<Float, String>
Generates a diff tree and calculates a diff score between two objects of the same class.
Instance Method Details
#diff_tree ⇒ String
Generates a diff tree between two objects of the same class
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/lutaml/model/comparable_model.rb', line 105 def diff_tree if @obj1.nil? && @obj2.nil? @root_tree = Tree.new("Both objects are nil") elsif @obj1.nil? @root_tree = Tree.new("First object is nil") format_single_value(@obj2, @root_tree, @obj2.class.to_s) elsif @obj2.nil? @root_tree = Tree.new("Second object is nil") format_single_value(@obj1, @root_tree, @obj1.class.to_s) else traverse_diff do |name, type, value1, value2, is_last| format_attribute_diff(name, type, value1, value2, is_last) end end @root_tree.to_s end |
#diff_with_score(obj1, obj2, **options) ⇒ Array<Float, String>
Generates a diff tree and calculates a diff score between two objects of the same class
128 129 130 131 132 |
# File 'lib/lutaml/model/comparable_model.rb', line 128 def diff_with_score(obj1, obj2, **) context = DiffContext.new(obj1, obj2, **) indent = [:indent] || "" [context.calculate_diff_score, context.diff_tree(indent)] end |