Class: StudFinder::Churn
- Inherits:
-
Object
- Object
- StudFinder::Churn
- Defined in:
- lib/stud_finder/churn.rb
Defined Under Namespace
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(repo_path:, files:, days:, stderr: $stderr) ⇒ Churn
constructor
A new instance of Churn.
Constructor Details
#initialize(repo_path:, files:, days:, stderr: $stderr) ⇒ Churn
Returns a new instance of Churn.
28 29 30 31 32 33 |
# File 'lib/stud_finder/churn.rb', line 28 def initialize(repo_path:, files:, days:, stderr: $stderr) @repo_path = File.(repo_path) @files = files @days = days @stderr = stderr end |
Instance Method Details
#call ⇒ Object
35 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 |
# File 'lib/stud_finder/churn.rb', line 35 def call stdout, _stderr, status = git_log raise Error, "Error: #{@repo_path} is not a git repository." unless status.success? counts = initial_counts file_set = counts.keys.to_h { |file| [file, true] } line_counts = initial_counts stdout.each_line do |line| line = line.strip next if line.empty? added, deleted, path = line.split("\t", 3) next if path.nil? relative = normalize_path(path) next unless file_set[relative] counts[relative] += 1 line_counts[relative] += added.to_i + deleted.to_i if added != '-' && numeric?(deleted) end Result.new( churn_commits: counts, churn_lines: line_counts, zero_inflated: zero_inflated?(counts), zero_percentage: zero_percentage(counts) ).tap { |result| warn_if_zero_inflated(result) } rescue Errno::ENOENT raise Error, 'Error: git not found in PATH.' end |