From 8257ec12626365d5e979b0c658017167ca61c36b Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Thu, 16 Aug 2012 19:42:09 +0200 Subject: [PATCH] Remove complexity in Differ --- lib/mutant/differ.rb | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/mutant/differ.rb b/lib/mutant/differ.rb index 3bc1c951..f0ddd2b7 100644 --- a/lib/mutant/differ.rb +++ b/lib/mutant/differ.rb @@ -12,7 +12,7 @@ module Mutant def diff output = '' @diffs.each do |piece| - hunk = Diff::LCS::Hunk.new(@old, @new, piece, CONTEXT_LINES, @length_difference) + hunk = Diff::LCS::Hunk.new(@old, @new, piece, CONTEXT_LINES, length_difference) output << hunk.diff(FORMAT) output << "\n" end @@ -48,11 +48,32 @@ module Mutant # @api private # def initialize(old, new) - @new, @old = new.lines.map(&:chomp), old.lines.map(&:chomp) - @length_difference = @new.size - @old.size + @old, @new = self.class.lines(old), self.class.lines(new) @diffs = Diff::LCS.diff(@old, @new) end + # Return length difference + # + # @return [Fixnum] + # + # @api private + # + def length_difference + @new.size - @old.size + end + + # Break up source into lines + # + # @param [String] source + # + # @return [Array] + # + # @api private + # + def self.lines(source) + source.lines.map { |line| line.chomp } + end + # Return colorized diff line # # @param [String] line