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
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/lutaml/model/comparable_model.rb', line 157 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.
150 151 152 |
# File 'lib/lutaml/model/comparable_model.rb', line 150 def highlight_diff @highlight_diff end |
#level ⇒ Object
Returns the value of attribute level.
151 152 153 |
# File 'lib/lutaml/model/comparable_model.rb', line 151 def level @level end |
#obj1 ⇒ Object (readonly)
Returns the value of attribute obj1.
150 151 152 |
# File 'lib/lutaml/model/comparable_model.rb', line 150 def obj1 @obj1 end |
#obj2 ⇒ Object (readonly)
Returns the value of attribute obj2.
150 151 152 |
# File 'lib/lutaml/model/comparable_model.rb', line 150 def obj2 @obj2 end |
#root_tree ⇒ Object
Returns the value of attribute root_tree.
151 152 153 |
# File 'lib/lutaml/model/comparable_model.rb', line 151 def root_tree @root_tree end |
#show_unchanged ⇒ Object (readonly)
Returns the value of attribute show_unchanged.
150 151 152 |
# File 'lib/lutaml/model/comparable_model.rb', line 150 def show_unchanged @show_unchanged end |
#tree_lines ⇒ Object
Returns the value of attribute tree_lines.
151 152 153 |
# File 'lib/lutaml/model/comparable_model.rb', line 151 def tree_lines @tree_lines end |
#use_colors ⇒ Object (readonly)
Returns the value of attribute use_colors.
150 151 152 |
# File 'lib/lutaml/model/comparable_model.rb', line 150 def use_colors @use_colors end |
Instance Method Details
#calculate_diff_score ⇒ Float
Calculates the normalized diff score
179 180 181 182 183 184 185 186 187 |
# File 'lib/lutaml/model/comparable_model.rb', line 179 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
170 171 172 173 174 175 |
# File 'lib/lutaml/model/comparable_model.rb', line 170 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 |