Class: Draghunt::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/draghunt/stats.rb

Constant Summary collapse

GIT_CMD =
'git log --numstat --pretty=oneline'
CLOC_CMD =
'cloc ./ --by-file --quiet --csv'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



26
27
28
# File 'lib/draghunt/stats.rb', line 26

def self.print
  puts new.all_stats.map(&:inspect).join("\n")
end

Instance Method Details

#all_statsObject



20
21
22
23
24
# File 'lib/draghunt/stats.rb', line 20

def all_stats
  git_stats.inject([]) do |m, (k, v)|
    m << [k, v, cloc_stats[k]] if cloc_stats.key?(k); m
  end.sort { |x, y| y[1] <=> x[1] }
end

#cloc_statsObject



14
15
16
17
18
# File 'lib/draghunt/stats.rb', line 14

def cloc_stats
  @cloc ||= `#{CLOC_CMD}`.lines.to_a[1..-1].inject({}) do |m, line|
    m[line.split(',')[1][2..-1]] = line.split(',').last.to_i; m
  end
end

#git_statsObject



6
7
8
9
10
11
12
# File 'lib/draghunt/stats.rb', line 6

def git_stats
  @git ||= `#{GIT_CMD}`.lines.inject({}) do |m, line|
    if match = line.match(/\A\d*\s.*\t(\S*)\n/)
      m[match[1]] = (m[match[1]] || 0) + 1
    end; m
  end
end