Guest User

Untitled

a guest
Nov 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. require 'diff/lcs'
  2. require 'diff/lcs/hunk'
  3.  
  4. data_old = [ 'hello', 'one', 'two', 'three', 'goodbye']
  5. data_new = [ 'hello', 'oNE', 'three', 'goodbye']
  6. diffs = Diff::LCS.diff(data_old, data_new)
  7.  
  8. file_length_difference = 0
  9. oldhunk = nil
  10. hunk = nil
  11. output = ''
  12.  
  13. diffs.each do |piece|
  14. begin
  15. hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, 3, file_length_difference)
  16. file_length_difference = hunk.file_length_difference
  17. next unless oldhunk
  18. if hunk.overlaps?(oldhunk)
  19. hunk.unshift(oldhunk)
  20. else
  21. output << oldhunk.diff(:unified)
  22. end
  23. ensure
  24. oldhunk = hunk
  25. output << "\n"
  26. end
  27. end
  28.  
  29. output << oldhunk.diff(:unified)
  30. output << "\n"
  31. puts output
Add Comment
Please, Sign In to add comment