Class: MGit::StatisticsCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/mgit/commands/statistics.rb

Instance Method Summary collapse

Methods inherited from Command

#check_arity, execute, instance_each, list, register_alias, register_command

Methods included from Output

#perror, #pinfo, #ptable, #pwarn

Instance Method Details

#arityObject



35
36
37
# File 'lib/mgit/commands/statistics.rb', line 35

def arity
  [nil, 0]
end

#descriptionObject



43
44
45
# File 'lib/mgit/commands/statistics.rb', line 43

def description
  'display authorship statistics for each repository and in total'
end

#execute(args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mgit/commands/statistics.rb', line 5

def execute(args)
  total_authors = {}
  total_punchcard = {}
  Registry.chdir_each do |repo|
    current_authors = {}
    current_punchcard = {}

    collect do |author, time, changes|
      current_authors[author] ||= 0
      current_authors[author] += changes

      total_punchcard[time.wday] ||= {}
      total_punchcard[time.wday][time.hour / 4] ||= 0
      total_punchcard[time.wday][time.hour / 4] += changes
    end

    print_authors current_authors, repo.name
    puts

    current_authors.each do |author, changes|
      total_authors[author] ||= 0
      total_authors[author] += changes
    end
  end

  print_authors total_authors, 'TOTAL'
  puts
  print_punchcard total_punchcard, 'TOTAL'
end

#usageObject



39
40
41
# File 'lib/mgit/commands/statistics.rb', line 39

def usage
  'statistics'
end