summaryrefslogtreecommitdiff
path: root/rake_helpers/code_statistics.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2006-06-28 23:05:18 +0000
committermurphy <murphy@rubychan.de>2006-06-28 23:05:18 +0000
commit72a8989da58b16566558a373a4cf582cd36b3872 (patch)
treefcda6647ec3db395f3cffc9d7ff6de9dd90802c0 /rake_helpers/code_statistics.rb
parentb5c6e09f9462acd5a8a98318c45bcc3f9114d137 (diff)
downloadcoderay-72a8989da58b16566558a373a4cf582cd36b3872.tar.gz
Fix:
HTML Scanner: Fixed a nasty bug with invalid entities. Thanks to Daniel Bovensiepen. Scanner: added Scanner.normify. Plugin: small documentation fix. Code statistic: added lib root folder rake_helpers/code_statistics.rb: added ability to include non-Ruby code in the statistics used it to count the mountain of test data There is some mixed space/tab indentation now. Complete 2-space-re-indentation will follow.
Diffstat (limited to 'rake_helpers/code_statistics.rb')
-rw-r--r--rake_helpers/code_statistics.rb53
1 files changed, 29 insertions, 24 deletions
diff --git a/rake_helpers/code_statistics.rb b/rake_helpers/code_statistics.rb
index 4c4b65c..b015403 100644
--- a/rake_helpers/code_statistics.rb
+++ b/rake_helpers/code_statistics.rb
@@ -45,15 +45,16 @@ private
DEFAULT_FILE_PATTERN = /\.rb$/
def calculate_statistics
- @pairs.inject({}) do |stats, (name, path, pattern)|
+ @pairs.inject({}) do |stats, (name, path, pattern, is_ruby_code)|
pattern ||= DEFAULT_FILE_PATTERN
path = File.join path, '*.rb'
- stats[name] = calculate_directory_statistics path, pattern
+ stats[name] = calculate_directory_statistics path, pattern, is_ruby_code
stats
end
end
- def calculate_directory_statistics directory, pattern = DEFAULT_FILE_PATTERN
+ def calculate_directory_statistics directory, pattern = DEFAULT_FILE_PATTERN, is_ruby_code = true
+ is_ruby_code = true if is_ruby_code.nil?
stats = Hash.new 0
Dir[directory].each do |file_name|
@@ -66,28 +67,32 @@ private
File.readlines(file_name).each do |line|
lines += 1
- case line
- when /^=end\b/
- comment_lines += 1
- in_comment_block = false
- when in_comment_block
- comment_lines += 1
- when /^\s*class\b/: classes += 1
- when /^\s*module\b/: modules += 1
- when /^\s*def\b/: methods += 1
- when /^\s*#/: comment_lines += 1
- when /^\s*$/: empty_lines += 1
- when /^=begin\b/
- in_comment_block = false
- comment_lines += 1
- when /^__END__$/
- in_comment_block = true
- end
+ if line[/^\s*$/]
+ empty_lines += 1
+ elsif is_ruby_code
+ case line
+ when /^=end\b/
+ comment_lines += 1
+ in_comment_block = false
+ when in_comment_block
+ comment_lines += 1
+ when /^\s*class\b/: classes += 1
+ when /^\s*module\b/: modules += 1
+ when /^\s*def\b/: methods += 1
+ when /^\s*#/: comment_lines += 1
+ when /^=begin\b/
+ in_comment_block = false
+ comment_lines += 1
+ when /^__END__$/
+ in_comment_block = true
+ end
+ end
end
codelines = lines - comment_lines - empty_lines
stats[:lines] += lines
+ stats[:comments] += comment_lines
stats[:codelines] += codelines
stats[:classes] += classes
stats[:modules] += modules
@@ -118,12 +123,12 @@ private
def print_header
print_splitter
- puts "| T=Test Name | Files | Lines | LOC | Classes | Modules | Methods | M/C | LOC/M |"
+ puts "| T=Test Name | Files | Lines | LOC | Comments | Classes | Modules | Methods | M/C | LOC/M |"
print_splitter
end
def print_splitter
- puts "+---------------------------+-------+-------+-------+---------+---------+---------+-----+-------+"
+ puts "+---------------------------+-------+-------+-------+----------+---------+---------+---------+-----+-------+"
end
def print_line name, statistics
@@ -136,8 +141,8 @@ private
name = " #{name}"
end
- line = "| %-25s | %5d | %5d | %5d | %7d | %7d | %7d | %3d | %5d |" % (
- [name, *statistics.values_at(:files, :lines, :codelines, :classes, :modules, :methods)] +
+ line = "| %-25s | %5d | %5d | %5d | %8d | %7d | %7d | %7d | %3d | %5d |" % (
+ [name, *statistics.values_at(:files, :lines, :codelines, :comments, :classes, :modules, :methods)] +
[m_over_c, loc_over_m] )
puts line