Class: RubocopDirector::FileStatsBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop_director/file_stats_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(rubocop_json:, update_counts:, config:) ⇒ FileStatsBuilder

Returns a new instance of FileStatsBuilder.



6
7
8
9
10
# File 'lib/rubocop_director/file_stats_builder.rb', line 6

def initialize(rubocop_json:, update_counts:, config:)
  @rubocop_json = rubocop_json
  @update_counts = update_counts
  @config = config
end

Instance Method Details

#buildObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rubocop_director/file_stats_builder.rb', line 12

def build
  update_weight = yield fetch_update_weight

  file_stats = files_with_offenses.map do |file|
    stats = {
      path: file["path"],
      updates_count: update_counts[file["path"]] || 0,
      offense_counts: file["offenses"].group_by { |offense| offense["cop_name"] }.transform_values(&:count)
    }

    stats[:cop_value] = yield find_refactoring_value(stats)

    stats
  end

  total_updates_count = file_stats.sum { |f| f[:updates_count] }

  file_stats = file_stats.each do |stats|
    stats[:value] = stats[:cop_value] * ((stats[:updates_count] / total_updates_count.to_f)**update_weight)
  end

  Success(file_stats.sort_by { _1[:value] }.reverse)
end