Class: GitStatistics::Formatters::Console
- Inherits:
-
Object
- Object
- GitStatistics::Formatters::Console
- Defined in:
- lib/git_statistics/formatters/console.rb
Instance Attribute Summary collapse
-
#commits ⇒ Object
Returns the value of attribute commits.
-
#config ⇒ Object
Returns the value of attribute config.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #add_row(string_or_array) ⇒ Object
- #author_info(total_authors) ⇒ Object
- #display! ⇒ Object
- #format_for_row(*columns) ⇒ Object
- #header_info ⇒ Object
-
#initialize(commits) ⇒ Console
constructor
A new instance of Console.
- #prepare_result_summary(sort, email, top_n = 0) ⇒ Object
- #print_header ⇒ Object
- #print_language_data(data) ⇒ Object
- #print_row(name, commit_info, language = '') ⇒ Object
- #print_summary(sort, email, top_n = 0) ⇒ Object
- #separator ⇒ Object
Constructor Details
#initialize(commits) ⇒ Console
Returns a new instance of Console.
7 8 9 10 11 |
# File 'lib/git_statistics/formatters/console.rb', line 7 def initialize(commits) @commits = commits @config = {} @output = [] end |
Instance Attribute Details
#commits ⇒ Object
Returns the value of attribute commits.
5 6 7 |
# File 'lib/git_statistics/formatters/console.rb', line 5 def commits @commits end |
#config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'lib/git_statistics/formatters/console.rb', line 5 def config @config end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
4 5 6 |
# File 'lib/git_statistics/formatters/console.rb', line 4 def output @output end |
Instance Method Details
#add_row(string_or_array) ⇒ Object
102 103 104 |
# File 'lib/git_statistics/formatters/console.rb', line 102 def add_row(string_or_array) output.concat Array(string_or_array) end |
#author_info(total_authors) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/git_statistics/formatters/console.rb', line 94 def () if config[:top_n] > 0 && config[:top_n] < add_row "Top #{config[:top_n]} authors(#{}) sorted by #{config[:sort]}" else add_row "All authors(#{}) sorted by #{config[:sort]}" end end |
#display! ⇒ Object
57 58 59 |
# File 'lib/git_statistics/formatters/console.rb', line 57 def display! output.join("\n") end |
#format_for_row(*columns) ⇒ Object
86 87 88 |
# File 'lib/git_statistics/formatters/console.rb', line 86 def format_for_row(*columns) @pattern % columns end |
#header_info ⇒ Object
80 81 82 83 84 |
# File 'lib/git_statistics/formatters/console.rb', line 80 def header_info add_row separator add_row format_for_row('Name/Email', 'Language', 'Commits', 'Additions', 'Deletions', 'Creates', 'Deletes', 'Renames', 'Copies', 'Merges') add_row separator end |
#prepare_result_summary(sort, email, top_n = 0) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/git_statistics/formatters/console.rb', line 13 def prepare_result_summary(sort, email, top_n = 0) # Default to a 0 if given a negative number to display top_n = 0 if top_n < 0 # Acquire data based on sort type and top # to show data = @commits.(sort.to_sym, top_n) raise 'Parameter for --sort is not valid' if data.nil? # Create config @config = { data: data, author_length: Utilities.max_length_in_list(data.keys, 17), language_length: Utilities.max_length_in_list(@commits.totals[:languages].keys, 8), sort: sort, email: email, top_n: top_n } # Acquire formatting pattern for output @pattern = "| %-#{config[:author_length]}s | %-#{config[:language_length]}s | %7s | %9s | %9s | %7s | %7s | %7s | %6s | %6s |" @config end |
#print_header ⇒ Object
75 76 77 78 |
# File 'lib/git_statistics/formatters/console.rb', line 75 def print_header (@commits.stats.size) header_info end |
#print_language_data(data) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/git_statistics/formatters/console.rb', line 61 def print_language_data(data) # Print information of each language for the data data[:languages].sort.each do |language, commit_data| print_row('', commit_data, language) end output end |
#print_row(name, commit_info, language = '') ⇒ Object
69 70 71 72 73 |
# File 'lib/git_statistics/formatters/console.rb', line 69 def print_row(name, commit_info, language = '') add_row format_for_row(name, language, commit_info[:commits], commit_info[:additions], commit_info[:deletions], commit_info[:added_files], commit_info[:deleted_files], commit_info[:renamed_files], commit_info[:copied_files], commit_info[:merges]) end |
#print_summary(sort, email, top_n = 0) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/git_statistics/formatters/console.rb', line 34 def print_summary(sort, email, top_n = 0) # Prepare and determine the config for the result summary based on parameters commit_totals = @commits.totals config = prepare_result_summary(sort, email, top_n) # Print query/header information print_header # Print per author information config[:data].each do |name, commit_data| print_row(name, commit_data) print_language_data(commit_data) end add_row separator print_row('Repository Totals', commit_totals) print_language_data(commit_totals) add_row separator display! end |
#separator ⇒ Object
90 91 92 |
# File 'lib/git_statistics/formatters/console.rb', line 90 def separator ('-' * 89) + ('-' * config[:author_length]) + ('-' * config[:language_length]) end |