Class: Reponaut::Application::Count

Inherits:
Command show all
Defined in:
lib/reponaut/commands/count.rb

Instance Attribute Summary

Attributes inherited from Command

#client, #repos, #username

Instance Method Summary collapse

Methods inherited from Command

inherited, #quit, subclasses

Constructor Details

#initialize(prog) ⇒ Count

Returns a new instance of Count.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/reponaut/commands/count.rb', line 6

def initialize(prog)
  prog.command(:count) do |c|
    c.syntax 'count [options] <username>'
    c.description "Shows a breakdown of a user's total number of repos"
    c.option 'ignore_forks', '-f', '--ignore-forks', 'Ignore forks'
    c.option 'sort_numerically', '-n', 'Sort by number of repos instead of alphabetically'

    c.action do |args, options|
      process(options, args)
    end
  end
end

Instance Method Details

#process(options, args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/reponaut/commands/count.rb', line 19

def process(options, args)
  super

  quit 3, "#{username} has no repositories" if repos.empty?

  stats = Reponaut::StatisticsCalculator.new(repos)
  counts = sort_counts(stats.language_counts.pairs, !!options['sort_numerically'])
  longest_label = counts.map { |e| e[0].length }.max
  longest_count = counts.map { |e| e[1].to_s.length }.max
  counts.each do |e|
    printf "%-*s     %*d\n", longest_label, e[0], longest_count, e[1]
  end
end