Module: Dyph::TwoWayDiffers::OutputConverter
- Extended by:
- OutputConverter
- Included in:
- OutputConverter
- Defined in:
- lib/dyph/two_way_differs/output_converter.rb
Overview
rubocop:disable Metrics/ModuleLength
Instance Method Summary collapse
- #convert_to_dyph_output(old_text, new_text) ⇒ Object
- #merge_results(old_text, new_text) ⇒ Object
- #objectify(merge_results) ⇒ Object
Instance Method Details
#convert_to_dyph_output(old_text, new_text) ⇒ Object
7 8 9 10 11 |
# File 'lib/dyph/two_way_differs/output_converter.rb', line 7 def convert_to_dyph_output(old_text, new_text) actions = merge_and_partition(old_text, new_text) selected_actions = extract_add_deletes_changes(actions) correct_offsets(selected_actions) end |
#merge_results(old_text, new_text) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dyph/two_way_differs/output_converter.rb', line 33 def merge_results(old_text, new_text) merged_text = [] if (new_text.empty?) no_new_text(old_text, merged_text) else prepend_old_text(old_text, merged_text) gather_up_actions(old_text, new_text, merged_text) end merged_text end |
#objectify(merge_results) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dyph/two_way_differs/output_converter.rb', line 13 def objectify(merge_results) merge_results.map do |result| action = result[:action] line = result[:line] old_index = result[:old_index] new_index = result[:new_index] case action when :add Dyph::Action::Add.new(value: line, old_index: old_index, new_index: new_index) when :delete Dyph::Action::Delete.new(value: line, old_index: old_index, new_index: new_index) when :no_change Dyph::Action::NoChange.new(value: line.text, old_index: old_index, new_index: new_index) else raise "unhandled action" end end end |