Class: Dyph::TwoWayDiffers::HeckelDiff
- Inherits:
-
Object
- Object
- Dyph::TwoWayDiffers::HeckelDiff
- Defined in:
- lib/dyph/two_way_differs/heckel_diff.rb
Defined Under Namespace
Classes: ChangeData
Class Method Summary collapse
-
.diff(left, right) ⇒ Object
Two-way diff based on the algorithm by P.
-
.execute_diff(old_text_array, new_text_array) ⇒ Object
Algorithm adapted from www.rad.upenn.edu/sbia/software/basis/apidoc/v1.2/diff3_8py_source.html.
Instance Method Summary collapse
-
#initialize(left, right) ⇒ HeckelDiff
constructor
A new instance of HeckelDiff.
- #perform_diff ⇒ Object
Constructor Details
#initialize(left, right) ⇒ HeckelDiff
Returns a new instance of HeckelDiff.
22 23 24 25 |
# File 'lib/dyph/two_way_differs/heckel_diff.rb', line 22 def initialize(left, right) @left = left @right = right end |
Class Method Details
.diff(left, right) ⇒ Object
Two-way diff based on the algorithm by P. Heckel.
17 18 19 20 |
# File 'lib/dyph/two_way_differs/heckel_diff.rb', line 17 def self.diff(left, right) differ = HeckelDiff.new(left,right) differ.perform_diff end |
.execute_diff(old_text_array, new_text_array) ⇒ Object
Algorithm adapted from www.rad.upenn.edu/sbia/software/basis/apidoc/v1.2/diff3_8py_source.html
7 8 9 10 11 12 |
# File 'lib/dyph/two_way_differs/heckel_diff.rb', line 7 def self.execute_diff(old_text_array, new_text_array) raise ArgumentError, "Argument is not an array." unless old_text_array.is_a?(Array) && new_text_array.is_a?(Array) diff_result = diff(old_text_array, new_text_array) # convert to typed differ's output (wrapped with change types eg. Add, Delete, Change) HeckelDiffWrapper.new(old_text_array, new_text_array, diff_result).convert_to_typed_ouput end |
Instance Method Details
#perform_diff ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/dyph/two_way_differs/heckel_diff.rb', line 27 def perform_diff unique_positions = identify_unique_postions unique_positions.sort!{ |a, b| a[0] <=> b[0] } # sort by the line in which the line was found in a left_change_pos, right_change_pos = find_next_change init_changes = ChangeData.new(left_change_pos, right_change_pos, []) final_changes = unique_positions.reduce(init_changes, &method(:get_differences)) final_changes.change_ranges end |