method
calculate_directory_statistics
v3.2.13 -
Show latest stable
- Class:
CodeStatistics
calculate_directory_statistics(directory, pattern = /.*\\.rb$/)private
No documentation available.
# File railties/lib/rails/code_statistics.rb, line 29
def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
Dir.foreach(directory) do |file_name|
if File.directory?(directory + "/" + file_name) and (/^\./ !~ file_name)
newstats = calculate_directory_statistics(directory + "/" + file_name, pattern)
stats.each { |k, v| stats[k] += newstats[k] }
end
next unless file_name =~ pattern
f = File.open(directory + "/" + file_name)
comment_started = false
while line = f.gets
stats["lines"] += 1
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
stats
end 1Note
Statistics
Thanks for the coding part it was really helpful for me, I would apply it on my project. http://www.koolchart.com