Class: MetricFu::FlogGenerator

Inherits:
Generator show all
Defined in:
lib/metric_fu/metrics/flog/generator.rb

Instance Attribute Summary

Attributes inherited from Generator

#options, #result, #template

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generator

#generate_result, generators, get_generator, #initialize, #metric, #metric_config, metric_directory, #metric_directory, not_implemented, #remove_excluded_files, #round_to_tenths, #run!

Constructor Details

This class inherits a constructor from MetricFu::Generator

Class Method Details

.metricObject



6
7
8
# File 'lib/metric_fu/metrics/flog/generator.rb', line 6

def self.metric
  :flog
end

Instance Method Details

#analyzeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/metric_fu/metrics/flog/generator.rb', line 19

def analyze
  @method_containers = {}
  @flogger.calculate
  @flogger.each_by_score do |full_method_name, score, operators|
    container_name = full_method_name.split("#").first
    path = @flogger.method_locations[full_method_name]
    if @method_containers[container_name]
      @method_containers[container_name].add_method(full_method_name, operators, score, path)
      @method_containers[container_name].add_path(path)
    else
      mc = MethodContainer.new(container_name, path)
      mc.add_method(full_method_name, operators, score, path)
      @method_containers[container_name] = mc
    end
  end
end

#emitObject



10
11
12
13
14
15
16
17
# File 'lib/metric_fu/metrics/flog/generator.rb', line 10

def emit
  parse_options = FlogCLI.parse_options [
    "--all",
    options[:continue] ? "--continue" : nil,
  ].compact
  @flogger = FlogCLI.new parse_options
  @flogger.flog *files_to_flog
end

#per_file_info(out) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/metric_fu/metrics/flog/generator.rb', line 43

def per_file_info(out)
  @method_containers.each_pair do |_klass, container|
    container.methods.each_pair do |_method_name, data|
      next if data[:path].nil?

      file, line = data[:path].split(":")

      out[file][line] << { type: :flog, description: "Score of %.2f" % data[:score] }
    end
  end
end

#to_hObject



36
37
38
39
40
41
# File 'lib/metric_fu/metrics/flog/generator.rb', line 36

def to_h
  sorted_containers = @method_containers.values.sort_by(&:highest_score).reverse
  { flog: { total: @flogger.total_score,
            average: @flogger.average,
            method_containers: sorted_containers.map(&:to_h) } }
end