Class: Zubat::Analizer

Inherits:
Object
  • Object
show all
Defined in:
lib/zubat/analizer.rb

Constant Summary collapse

AnalizedResult =
Data.define(:label, :commit, :stat)
Stat =
Data.define(:stat) do
  # @return [Float]
  def complexity_average(file)
    stat.fetch(file, {}).fetch(:average, nil)
  end

  # @return [Float]
  def complexity_total(file)
    stat.fetch(file, {}).fetch(:total_score, nil)
  end

  def smell_scores(file)
    stat.fetch(file, {}).fetch(:smells, {})
  end

  def smell_score(file, label)
    stat.fetch(file).fetch(:smells).fetch(label, 0)
  end

  def diff(file)
    stat.fetch(file, {}).fetch(:diff, nil)
  end

  def each(*, **, &block)
    stat.each(*, **, &block)
  end
end

Instance Method Summary collapse

Instance Method Details

#analize(files:, commit:) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/zubat/analizer.rb', line 36

def analize(files:, commit:)
  stat = {}

  files.each do |file|
    diff = commit.diff(file:)

    next if diff.empty?

    stat[file] = {}

    stat[file].merge!(diff:)

    code = commit.show(file:)

    next unless RubyCode.new(code:).valid?

    FlogWrapper.new.examine(code).then do |examined|
      stat[file][:average] = examined.average
      stat[file][:total_score] = examined.total_score
    end

    stat[file][:smells] = ReekWrapper.new.examine(code).map(&:smell_type).tally
  end

  stat = Stat.new(stat:)

  AnalizedResult.new(label: "#{commit.time.iso8601} (#{commit.sha})",
                     commit:,
                     stat:)
end