Module: Linecounter::Analyzer

Defined in:
lib/linecounter/analyzer.rb

Class Method Summary collapse

Class Method Details

.run(repo_path:, min_loc:, since:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/linecounter/analyzer.rb', line 18

def run(repo_path:, min_loc:, since:)
  rows = []
  structure_overview = Hash.new(0)
  structure_item_loc_overview = Hash.new(0)
  structure_item_counts_overview = Hash.new(0)

  Scanner.ruby_files(repo_path).each do |file|
    content = File.read(File.join(repo_path, file)) rescue next
    size = Scanner.loc(content)
    next if size < min_loc

    breakdown = BranchAnalyzer.breakdown(content)
    b = breakdown.values.sum
    c = Git.churn(repo_path, file, since)
    structures, structure_item_counts, structure_item_loc = StructureAnalyzer.counts(content)
    structures.each { |k, v| structure_overview[k] += v }
    structure_item_loc.each { |k, v| structure_item_loc_overview[k] += v }
    structure_item_counts.each { |k, v| structure_item_counts_overview[k] += v }

    rows << {
      file: file,
      loc: size,
      branches: b,
      branch_breakdown: breakdown,
      structures: structures,
      structure_item_counts: structure_item_counts,
      structure_item_loc: structure_item_loc,
      churn: c
    }
  end

  rows.sort_by! { |r| [-r[:churn], -r[:branches], -r[:loc]] }

  Result.new(
    rows: rows,
    structure_overview: structure_overview,
    structure_item_loc_overview: structure_item_loc_overview,
    structure_item_counts_overview: structure_item_counts_overview
  )
end