summaryrefslogtreecommitdiffstats
path: root/tasks/stats.rake
blob: 19ffd8ec815b1e5ab404899227bc53744f83c1a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    
desc 'lines and words count of real ruby code ( no empty lines or comments )'
task :stats do
    pattern = Regexp.new("^\s*(?:#.*)?$")
#    count_proc = Proc.new do |path|
#        Dir[path].collect { |f| File.open(f).readlines.reject { |l| l =~ pattern }.size }.inject(0) { |sum,n| sum+=n }
#    end
    stat_proc = Proc.new do |files,name|
        lines=0
        words=0
        files.each { |fn| open(fn){ |f| f.each{ |line|
            begin
                lines += 1
                words += line.split(' ').size
            end if not pattern.match(line)
        } } }
        puts "#{ format('%10s',name)} => #{format('%7d',lines)} code lines, #{format('%7d',words)} words."
    end
    stat_proc.call BIN_FILES, 'bin'
    stat_proc.call LIB_FILES, 'lib'
    stat_proc.call TEST_FILES, 'test'
    stat_proc.call EXT_FILES, 'ext'

end