lib/attractor/calculators/base_calculator.rb in attractor-2.0.5 vs lib/attractor/calculators/base_calculator.rb in attractor-2.1.0
- old
+ new
@@ -1,29 +1,31 @@
# frozen_string_literal: true
-require 'churn/calculator'
+require "churn/calculator"
-require 'attractor/value'
+require "attractor/value"
module Attractor
# calculates churn and complexity
class BaseCalculator
attr_reader :type
- def initialize(file_prefix: '', file_extension: 'rb', minimum_churn_count: 3, start_ago: '5y')
+ def initialize(file_prefix: "", ignores: "", file_extension: "rb", minimum_churn_count: 3, start_ago: "5y")
@file_prefix = file_prefix
@file_extension = file_extension
@minimum_churn_count = minimum_churn_count
@start_date = Date.today - Attractor::DurationParser.new(start_ago).duration
+ @ignores = ignores
end
def calculate
churn = ::Churn::ChurnCalculator.new(
file_extension: @file_extension,
file_prefix: @file_prefix,
minimum_churn_count: @minimum_churn_count,
- start_date: @start_date
+ start_date: @start_date,
+ ignores: @ignores
).report(false)
churn[:churn][:changes].map do |change|
complexity, details = yield(change)
Value.new(file_path: change[:file_path],
@@ -37,13 +39,13 @@
private
def git_history_for_file(file_path:, limit: 10)
history = `git log --oneline -n #{limit} -- #{file_path}`
history.split("\n")
- .map do |log_entry|
+ .map do |log_entry|
log_entry.partition(/\A(\S+)\s/)
- .map(&:strip)
- .reject(&:empty?)
+ .map(&:strip)
+ .reject(&:empty?)
end
end
end
end