Class: Multidiff::Differ
- Inherits:
-
Object
- Object
- Multidiff::Differ
- Defined in:
- lib/multidiff/differ.rb
Constant Summary collapse
- OVERRIDE_ACTION =
Hash.new { |hash, key| hash[key] = key }.merge('!' => '*', '=' => ' ')
Class Method Summary collapse
Class Method Details
.diff(files) ⇒ Object
7 8 9 10 11 |
# File 'lib/multidiff/differ.rb', line 7 def self.diff(files) base = files.shift files.map { |file| Diff::LCS.sdiff(base, file) } end |
.pretty_diff(files) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/multidiff/differ.rb', line 13 def self.pretty_diff(files) diff(files).map do |changes| changes.each_with_index.map do |change, line| text = if change.action == '!' "#{change.old_element}|#{change.new_element}" else change.old_element || change.new_element end "#{line.next}\t#{OVERRIDE_ACTION[change.action]}\t#{text}" end end end |