Last active
January 20, 2017 08:40
-
-
Save andyjeffries/22ededab8ef58b0fe50f7d56bd5dae69 to your computer and use it in GitHub Desktop.
Lines of code
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
#!/usr/bin/ruby | |
def count_lines(filename, type) | |
lines = File.read(filename).force_encoding('BINARY').split("\n") | |
lines.delete_if {|line| line[/^\s*$/]} | |
case type | |
when :ruby | |
lines.delete_if {|line| line[/^\s*#/]} | |
when :go | |
lines.delete_if {|line| line[/^\s*\/\/$/]} | |
when :cucumber | |
lines.delete_if {|line| line[/^\s*#/]} | |
when :perl | |
lines.delete_if {|line| line[/^\s*#/]} | |
when :html | |
lines.delete_if {|line| line[/^\s*<!\-\-.*\-\->\s*$/]} | |
when :js | |
lines.delete_if {|line| line[/^\s*\/\/$/]} | |
when :css | |
lines.delete_if {|line| line[/^\s*\/\//]} | |
lines.delete_if {|line| line[/^\s*\/\*.*\*\/\s*$/]} | |
end | |
lines.count | |
end | |
ruby_lines = 0 | |
cucumber_lines = 0 | |
perl_lines = 0 | |
go_lines = 0 | |
html_lines = 0 | |
css_lines = 0 | |
js_lines = 0 | |
Dir['**/*'].each do |file| | |
next if file[%r{^vendor/}] | |
next if file[%r{^Godeps/}] | |
if File.file?(file) | |
if file[/\.rb$/] | |
ruby_lines += count_lines(file, :ruby) | |
elsif file[/\.go$/] | |
go_lines += count_lines(file, :go) | |
elsif file[/\.(feature)$/] | |
cucumber_lines += count_lines(file, :cucumber) | |
elsif file[/\.(pl|pm)$/] | |
perl_lines += count_lines(file, :perl) | |
elsif file[/\.js(\.erb)?$/] | |
js_lines += count_lines(file, :js) | |
elsif file[/\.css(\.sass)?$/] | |
css_lines += count_lines(file, :css) | |
elsif file[/\.html(\.erb)?$/] | |
html_lines += count_lines(file, :erb) | |
end | |
end | |
end | |
puts "Ruby: #{ruby_lines}" | |
puts "Go: #{go_lines}" | |
puts "Cucumber: #{cucumber_lines}" | |
puts "HTML: #{html_lines}" | |
puts "CSS: #{css_lines}" | |
puts "JS: #{js_lines}" | |
puts "Perl: #{perl_lines}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment