lib/analdiffist/flog_parser.rb in analdiffist-0.3.0 vs lib/analdiffist/flog_parser.rb in analdiffist-0.4.0

- old
+ new

@@ -5,11 +5,12 @@ @paths = paths @flog_threshold = threshold end def problems - f = Flog.new + f = Flog.new :continue => true + f.flog(@paths) problems = [] f.each_by_score{|class_method, score, ignore_for_now| problems << FlogProblem.new(class_method, score, @flog_threshold)} problems #problems.select {|p| p.score >= @flog_threshold} @@ -27,14 +28,16 @@ def type 'flog score' end def diff other - return nil if score < @flog_threshold - return FlogDiff.new(@context, 0, score) if other.nil? - - return nil if other.score >= score + if other.nil? + return nil if score < @flog_threshold + return FlogDiff.new(@context, 0, score) + end + return nil if other.score == score + return nil if score < @flog_threshold && other.score < @flog_threshold FlogDiff.new(@context, other.score, score) end def description "Flog: #{score}" @@ -51,11 +54,38 @@ def score (@current_score - @previous_score).round(1) end + def invert! + score = 0 - (score || 0) + self + end + def description(mode = :added) - indicator = (mode == :added) ? "+" : "-" + indicator = (mode == :added) ? "+" : "" "Flog: #{@current_score.round(1)} (#{indicator}#{(@current_score - @previous_score).round(1)})" + end + end + + class InvertedDiff + def initialize inner + @inner = inner + end + + def context + @inner.context + end + + def score + 0-@inner.score + end + + def type + @inner.type + end + + def description(mode = :added) + @inner.description(mode) end end end