Added v 0.4.0 snapshot.
[twitter4r-core.git] / tasks / stats.rake
blobdb0d7904fd965afb4f961dbbeaf9e7549834c610
1 require('code_statistics')
3 class CodeStatistics
4   TEST_TYPES = %w(Specs) unless defined?(TEST_TYPES)
6   def to_embedded_html
7     output = "<table id=\"stats\">\n"
8     output << "\t<th><td>Name</td><td>Lines</td><td>LOC</td><td>Classes</td><td>Methods</td><td>M/C</td><td>LOC/M</td></th>\n"
9     @pairs.each { |p| output << html_row(p) }
10     output << "</table>"
11     output
12   end
14   private
15     def html_row(pair)
16       stats = @statistics[pair.first]
17       methods = stats["methods"]
18       classes = stats["classes"]
19       loc = stats["codelines"]
20       lines = stats["lines"]
21       mpc = methods/classes
22       lpm = loc/methods
23       
24       "\t<tr><td>#{pair.first}</td><td>#{lines}</td><td>#{loc}</td><td>#{classes}</td><td>#{methods}</td><td>#{mpc}</td><td>#{lpm}</td></tr>\n"
25     end
26 end
28 namespace :stats do
29   STATS_DIRECTORIES = [
30     %w(Library\ Code   lib),
31     %w(Specs        spec)
32   ].collect { |name, dir| [ name, "./#{dir}" ] }.select { |name, dir| File.directory?(dir) }
34   desc "Report code statistics (KLOCs, etc) for code"
35   task :default do
36     verbose = true
37     CodeStatistics.new(*STATS_DIRECTORIES).to_s
38   end
40   desc "Report code statistics (KLOCs, etc) for code in HTML"
41   task :html do
42     puts CodeStatistics.new(*STATS_DIRECTORIES).to_embedded_html
43   end
44 end