Module: Lutaml::Model::ComparableModel::ClassMethods
- 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
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/lutaml/model/comparable_model.rb', line 79 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
102 103 104 105 106 |
# File 'lib/lutaml/model/comparable_model.rb', line 102 def diff_with_score(obj1, obj2, **) context = DiffContext.new(obj1, obj2, **) indent = [:indent] || "" [context.calculate_diff_score, context.diff_tree(indent)] end |