Guest User

Untitled

a guest
Jun 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. module LocCounter
  4. extend self
  5.  
  6. def print_loc_for_glob(glob)
  7. count = 0
  8.  
  9. Dir[*glob].each do |file|
  10. next if File.directory?(file)
  11.  
  12. lines = loc(file)
  13.  
  14. out "#{ file } has #{ lines } lines"
  15. count += lines
  16. end
  17.  
  18. puts
  19. out "Total LOC: #{ count }"
  20. end
  21.  
  22. def loc(file)
  23. data = File.read(file)
  24. code = data.split("\n").reject { |l| l =~ /^\s*$/ or l =~ /^\s*\#/ }
  25. code.size
  26. end
  27.  
  28. def out(str)
  29. puts "-----> #{str}"
  30. end
  31. end
  32.  
  33. LocCounter.print_loc_for_glob(ARGV)
Add Comment
Please, Sign In to add comment