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.
Instance Method Summary collapse
- #format_for_row(*columns) ⇒ Object
- #get_author_info(total_authors) ⇒ Object
- #get_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 |
# File 'lib/git_statistics/formatters/console.rb', line 7 def initialize(commits) @commits = commits 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 |
Instance Method Details
#format_for_row(*columns) ⇒ Object
81 82 83 |
# File 'lib/git_statistics/formatters/console.rb', line 81 def format_for_row(*columns) @pattern % columns end |
#get_author_info(total_authors) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/git_statistics/formatters/console.rb', line 89 def () if config[:top_n] > 0 && config[:top_n] < return "Top #{config[:top_n]} authors(#{}) sorted by #{config[:sort]}" end "All authors(#{}) sorted by #{config[:sort]}" end |
#get_header_info ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/git_statistics/formatters/console.rb', line 73 def get_header_info headers = [] headers << separator headers << format_for_row('Name/Email', 'Language', 'Commits', 'Additions', 'Deletions', 'Creates', 'Deletes', 'Renames', 'Copies', 'Merges') headers << separator headers end |
#prepare_result_summary(sort, email, top_n = 0) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/git_statistics/formatters/console.rb', line 11 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
66 67 68 69 70 71 |
# File 'lib/git_statistics/formatters/console.rb', line 66 def print_header output = [] output << (@commits.stats.size) output << get_header_info output end |
#print_language_data(data) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/git_statistics/formatters/console.rb', line 51 def print_language_data(data) output = [] # Print information of each language for the data data[:languages].each do |language, commit_data| output << print_row("", commit_data, language) end output end |
#print_row(name, commit_info, language = '') ⇒ Object
60 61 62 63 64 |
# File 'lib/git_statistics/formatters/console.rb', line 60 def print_row(name, commit_info, language = '') format_for_row(name, language, commit_info[:commits], commit_info[:additions], commit_info[:deletions], commit_info[:create], commit_info[:delete], commit_info[:rename], commit_info[:copy], commit_info[:merges]) end |
#print_summary(sort, email, top_n = 0) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/git_statistics/formatters/console.rb', line 32 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 output = print_header # Print per author information config[:data].each do |name, commit_data| output << print_row(name, commit_data) output << print_language_data(commit_data) end output << separator output << print_row("Repository Totals", commit_totals) output << print_language_data(commit_totals) output.flatten.join("\n") end |
#separator ⇒ Object
85 86 87 |
# File 'lib/git_statistics/formatters/console.rb', line 85 def separator "-" * 89 + "-"*config[:author_length] + "-"*config[:language_length] end |