Skip to content

Instantly share code, notes, and snippets.

@timoteoponce
Created September 14, 2011 13:02
Show Gist options
  • Save timoteoponce/1216487 to your computer and use it in GitHub Desktop.
Save timoteoponce/1216487 to your computer and use it in GitHub Desktop.
LOC counter in Ruby
# 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