Created
September 14, 2011 13:02
-
-
Save timoteoponce/1216487 to your computer and use it in GitHub Desktop.
LOC counter in Ruby
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
# lines of code | |
def count_files( base_dir ) | |
file_names = Dir.glob( base_dir + "/**/*.{java,py,sh,pl}") | |
puts "Counting LOC in [ #{file_names.length} ] files in folder : #{base_dir}" | |
total_count = 0 | |
file_names.each do |file| | |
total_count += count_file file | |
end | |
puts "Total LOC: #{total_count}" | |
end | |
def count_file( file_name ) | |
# puts "Counting file [ #{file_name} ]" | |
file = File.open(file_name) | |
count = 0 | |
file.each do |line| | |
real_line = line.delete(" \n\r") | |
unless real_line.empty? | |
count += 1 | |
end | |
end | |
return count | |
end | |
count_files "similar_apps/raw_project1" | |
count_files "similar_apps/raw_project2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment