Class: GitEvolution::ReportPresenter
- Inherits:
-
Object
- Object
- GitEvolution::ReportPresenter
- Defined in:
- lib/git_evolution/report_presenter.rb
Instance Method Summary collapse
- #calculate_ownership! ⇒ Object
-
#initialize(commits) ⇒ ReportPresenter
constructor
A new instance of ReportPresenter.
- #print ⇒ Object
- #print_changes_ownership ⇒ Object
- #print_commit_ownership ⇒ Object
- #print_commits ⇒ Object
- #sort_ownership! ⇒ Object
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.] = @ownership[:commits][commit.] + 1 @ownership[:changes][commit.] = @ownership[:changes][commit.] + commit.additions + commit.deletions end sort_ownership! end |
#print ⇒ Object
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 |
#print_changes_ownership ⇒ Object
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 |, count| puts "#{author} - #{count}/#{total_changes} (#{(count.to_f / total_changes * 100).round(2)}%)" end end |
#print_commit_ownership ⇒ Object
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 |, count| puts "#{author} - #{count}/#{@commits.size} (#{(count.to_f / @commits.size * 100).round(2)}%)" end end |
#print_commits ⇒ Object
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 |