Class: GitEvolution::ReportPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/git_evolution/report_presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(commits) ⇒ ReportPresenter



3
4
5
6
7
8
# File 'lib/git_evolution/report_presenter.rb', line 3

def initialize(commits)
  @commits = commits
  @ownership = { commits: Hash.new(0), changes: Hash.new(0) }

  calculate_ownership!
end

Instance Method Details

#calculate_ownership!Object



49
50
51
52
53
54
55
56
# File 'lib/git_evolution/report_presenter.rb', line 49

def calculate_ownership!
  @commits.each do |commit|
    @ownership[:commits][commit.author] = @ownership[:commits][commit.author] + 1
    @ownership[:changes][commit.author] = @ownership[:changes][commit.author] + commit.additions + commit.deletions
  end

  sort_ownership!
end


10
11
12
13
14
15
16
17
18
19
# File 'lib/git_evolution/report_presenter.rb', line 10

def print
  print_commits
  puts
  puts '-' * 80
  puts
  print_commit_ownership
  puts
  print_changes_ownership
  puts
end


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/git_evolution/report_presenter.rb', line 37

def print_changes_ownership
  puts 'Ownership (Changes):'

  total_additions = @commits.inject(0) { |sum, commit| sum + commit.additions }
  total_deletions = @commits.inject(0) { |sum, commit| sum + commit.deletions }
  total_changes = total_additions + total_deletions

  @ownership[:changes].each do |author, count|
    puts "#{author} - #{count}/#{total_changes} (#{(count.to_f / total_changes * 100).round(2)}%)"
  end
end


30
31
32
33
34
35
# File 'lib/git_evolution/report_presenter.rb', line 30

def print_commit_ownership
  puts 'Ownership (Commits):'
  @ownership[:commits].each do |author, count|
    puts "#{author} - #{count}/#{@commits.size} (#{(count.to_f / @commits.size * 100).round(2)}%)"
  end
end


21
22
23
24
25
26
27
28
# File 'lib/git_evolution/report_presenter.rb', line 21

def print_commits
  puts 'Commits:'
  @commits.each do |commit|
    puts "#{commit.author} (#{commit.date}) - #{commit.sha}"
    puts "#{commit.subject}"
    puts
  end
end

#sort_ownership!Object



58
59
60
61
62
# File 'lib/git_evolution/report_presenter.rb', line 58

def sort_ownership!
  @ownership.keys.each do |keys|
    @ownership[keys] = @ownership[keys].sort { |a,b| b[1] <=> a[1] }.to_h
  end
end