Class: Twigg::Command::Stats
- Inherits:
-
Twigg::Command
- Object
- Twigg::Command
- Twigg::Command::Stats
- Includes:
- Util
- Defined in:
- lib/twigg/command/stats.rb
Constant Summary
Constants inherited from Twigg::Command
EASTER_EGGS, PUBLIC_SUBCOMMANDS, SUBCOMMANDS
Instance Method Summary collapse
-
#initialize(*args) ⇒ Stats
constructor
A new instance of Stats.
- #run ⇒ Object
-
#stats_widths(master_set) ⇒ Object
Returns a tuple of “column” widths with sufficient space to represent the commit count, addition count and deletion count for the given Twigg::CommitSet, ‘master_set`.
Methods included from Util
Methods inherited from Twigg::Command
Constructor Details
#initialize(*args) ⇒ Stats
Returns a new instance of Stats.
6 7 8 9 10 11 12 |
# File 'lib/twigg/command/stats.rb', line 6 def initialize(*args) super Help.new('stats').run! if @args.size > 2 @repositories_directory = @args[0] || Config.repositories_directory @days = (@args[1] || Config.default_days).to_i end |
Instance Method Details
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 |
# File 'lib/twigg/command/stats.rb', line 14 def run master_set = Twigg::Gatherer.gather(@repositories_directory, @days) w0, w1, w2 = stats_widths(master_set) master_set..each do || = [:author] commit_set = [:commit_set] puts '%5s %-24s %s' % [ number_with_delimiter(commit_set.count), , commit_set.decorate.breakdown(html: false), ] if @verbose puts commit_set.each do |commit| puts (' ' * w0) + " %#{w1}s, %#{w2}s %s [%s]" % [ "+#{number_with_delimiter commit.stat[:additions]}", "-#{number_with_delimiter commit.stat[:deletions]}", commit.subject, commit.repo.name, ] end totals = (' ' * w0) + " %#{w1}s, %#{w2}s" % [ "+#{number_with_delimiter commit_set.additions}", "-#{number_with_delimiter commit_set.deletions}", ] puts '-' * totals.length puts totals puts end end if @verbose totals = "%-#{w0}s %#{w1}s, %#{w2}s" % [ number_with_delimiter(master_set.count), "+#{number_with_delimiter master_set.additions}", "-#{number_with_delimiter master_set.deletions}", ] puts '=' * totals.length puts totals else totals = "%#{w0}s" % number_with_delimiter(master_set.count) puts '-' * totals.length puts totals end end |
#stats_widths(master_set) ⇒ Object
Returns a tuple of “column” widths with sufficient space to represent the commit count, addition count and deletion count for the given Twigg::CommitSet, ‘master_set`.
66 67 68 69 70 71 72 |
# File 'lib/twigg/command/stats.rb', line 66 def stats_widths(master_set) [ number_with_delimiter(master_set.count).length, number_with_delimiter(master_set.additions).length + 1, # room for sign number_with_delimiter(master_set.deletions).length + 1, # room for sign ] end |