Skip to content
Browse files

Merge pull request #3731 from HeeL/master

code stats calculation
  • Loading branch information...
2 parents e9f63c5 + d78a702 commit 8549f7a4f0c30c37050666f5661ea9e270a298fd @wycats wycats committed Nov 23, 2011
Showing with 14 additions and 3 deletions.
  1. +14 −3 railties/lib/rails/code_statistics.rb
View
17 railties/lib/rails/code_statistics.rb
@@ -38,11 +38,22 @@ def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
next unless file_name =~ pattern
f = File.open(directory + "/" + file_name)
-
+ comment_started = false
while line = f.gets
stats["lines"] += 1
- stats["classes"] += 1 if line =~ /class [A-Z]/
- stats["methods"] += 1 if line =~ /def [a-z]/
+ if(comment_started)
+ if line =~ /^=end/
+ comment_started = false
+ end
+ next
+ else
+ if line =~ /^=begin/
+ comment_started = true
+ next
+ end
+ end
+ stats["classes"] += 1 if line =~ /^\s*class\s+[_A-Z]/
+ stats["methods"] += 1 if line =~ /^\s*def\s+[_a-z]/
stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
end
end

2 comments on commit 8549f7a

@josevalim
Ruby on Rails member

No tests bro :(

@wycats
Ruby on Rails member
wycats commented on 8549f7a Nov 23, 2011

Good point. @HeeL, can you add some tests please :)

Please sign in to comment.
Something went wrong with that request. Please try again.