Class: Lutaml::Model::ComparableModel::DiffContext
- Inherits:
-
Object
- Object
- Lutaml::Model::ComparableModel::DiffContext
- Defined in:
- lib/lutaml/model/comparable_model.rb
Overview
DiffContext handles the comparison between two objects
Instance Attribute Summary collapse
-
#highlight_diff ⇒ Object
readonly
Returns the value of attribute highlight_diff.
-
#level ⇒ Object
Returns the value of attribute level.
-
#obj1 ⇒ Object
readonly
Returns the value of attribute obj1.
-
#obj2 ⇒ Object
readonly
Returns the value of attribute obj2.
-
#root_tree ⇒ Object
Returns the value of attribute root_tree.
-
#show_unchanged ⇒ Object
readonly
Returns the value of attribute show_unchanged.
-
#tree_lines ⇒ Object
Returns the value of attribute tree_lines.
-
#use_colors ⇒ Object
readonly
Returns the value of attribute use_colors.
Instance Method Summary collapse
-
#calculate_diff_score ⇒ Float
Calculates the normalized diff score.
-
#diff_tree(indent = "") ⇒ String
Generates a diff tree between the two objects.
-
#initialize(obj1, obj2, **options) ⇒ DiffContext
constructor
Initializes a new DiffContext.
Constructor Details
#initialize(obj1, obj2, **options) ⇒ DiffContext
Initializes a new DiffContext
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/lutaml/model/comparable_model.rb', line 117 def initialize(obj1, obj2, **) @obj1 = obj1 @obj2 = obj2 @show_unchanged = .fetch(:show_unchanged, false) @highlight_diff = .fetch(:highlight_diff, false) @use_colors = .fetch(:use_colors, true) @level = 0 @tree_lines = [] @root_tree = Tree.new(obj1.class.to_s) end |
Instance Attribute Details
#highlight_diff ⇒ Object (readonly)
Returns the value of attribute highlight_diff.
110 111 112 |
# File 'lib/lutaml/model/comparable_model.rb', line 110 def highlight_diff @highlight_diff end |
#level ⇒ Object
Returns the value of attribute level.
111 112 113 |
# File 'lib/lutaml/model/comparable_model.rb', line 111 def level @level end |
#obj1 ⇒ Object (readonly)
Returns the value of attribute obj1.
110 111 112 |
# File 'lib/lutaml/model/comparable_model.rb', line 110 def obj1 @obj1 end |
#obj2 ⇒ Object (readonly)
Returns the value of attribute obj2.
110 111 112 |
# File 'lib/lutaml/model/comparable_model.rb', line 110 def obj2 @obj2 end |
#root_tree ⇒ Object
Returns the value of attribute root_tree.
111 112 113 |
# File 'lib/lutaml/model/comparable_model.rb', line 111 def root_tree @root_tree end |
#show_unchanged ⇒ Object (readonly)
Returns the value of attribute show_unchanged.
110 111 112 |
# File 'lib/lutaml/model/comparable_model.rb', line 110 def show_unchanged @show_unchanged end |
#tree_lines ⇒ Object
Returns the value of attribute tree_lines.
111 112 113 |
# File 'lib/lutaml/model/comparable_model.rb', line 111 def tree_lines @tree_lines end |
#use_colors ⇒ Object (readonly)
Returns the value of attribute use_colors.
110 111 112 |
# File 'lib/lutaml/model/comparable_model.rb', line 110 def use_colors @use_colors end |
Instance Method Details
#calculate_diff_score ⇒ Float
Calculates the normalized diff score
139 140 141 142 143 144 145 146 147 |
# File 'lib/lutaml/model/comparable_model.rb', line 139 def calculate_diff_score total_score = 0 total_attributes = 0 traverse_diff do |_, _, value1, value2, _| total_score += calculate_attribute_score(value1, value2) total_attributes += 1 end total_attributes.positive? ? total_score / total_attributes : 0 end |
#diff_tree(indent = "") ⇒ String
Generates a diff tree between the two objects
130 131 132 133 134 135 |
# File 'lib/lutaml/model/comparable_model.rb', line 130 def diff_tree(indent = "") traverse_diff do |name, type, value1, value2, is_last| format_attribute_diff(name, type, value1, value2, is_last) end @root_tree.to_s(indent) end |