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

- old
+ new

@@ -8,36 +8,41 @@ def problems f = Flog.new f.flog(@paths) problems = [] - f.each_by_score{|class_method, score, ignore_for_now| problems << FlogProblem.new(class_method, score)} - problems.select {|p| p.score >= @flog_threshold} + 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} end end class FlogProblem attr_accessor :context, :score - def initialize class_method, score + def initialize class_method, score, threshold = 10 @context = class_method || '(none)' - @score = score + @score = score.round(1) + @flog_threshold = threshold end def type 'flog score' end def diff other - return self if other.nil? + return nil if score < @flog_threshold + return FlogDiff.new(@context, 0, score) if other.nil? + return nil if other.score >= score FlogDiff.new(@context, other.score, score) end def description - "Flog score: #{score}" + "Flog: #{score}" end end + class FlogDiff attr_accessor :context, :score def initialize context, previous_score, current_score @context = context @current_score = current_score @@ -46,10 +51,11 @@ def score (@current_score - @previous_score).round(1) end - def description - "Flog: #{@current_score.round(1)} (+#{(@current_score - @previous_score).round(1)})" + def description(mode = :added) + indicator = (mode == :added) ? "+" : "-" + "Flog: #{@current_score.round(1)} (#{indicator}#{(@current_score - @previous_score).round(1)})" end end end