Created
June 17, 2012 20:13
-
-
Save louismullie/2945588 to your computer and use it in GitHub Desktop.
Count the number of files, lines of code and comments in a Ruby project.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
o = 0 # Number of files | |
n = 0 # Number of lines of code | |
m = 0 # Number of lines of comments | |
files = Dir.glob('/path/to/dir/**/*.rb') | |
files.each do |f| | |
next if FileTest.directory?(f) | |
o += 1 | |
i = 0 | |
lines = [] | |
File.new(f).each_line do |line| | |
if line.strip[0] == '#' | |
m += 1 | |
next | |
end | |
lines << line | |
i += 1 | |
end | |
n += i | |
end | |
puts "#{o.to_s} files." | |
puts "#{n.to_s} lines of code." | |
puts "#{(n.to_f/o.to_f).round(2)} LOC/file." | |
puts "#{m.to_s} lines of comments." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment