Skip to content

Instantly share code, notes, and snippets.

@michaelfeathers
Created October 5, 2012 07:45
Show Gist options
  • Save michaelfeathers/3838607 to your computer and use it in GitHub Desktop.
Save michaelfeathers/3838607 to your computer and use it in GitHub Desktop.
Turbulence Light-er
def complexity filename
File.read(filename).lines.grep(/^([ \t]*)/) { $1 }.map(&:length).reduce(0, :+)
end
filenames = `git log --name-only | grep \.rb$`.lines \
.map(&:strip) \
.reject { |fn| fn.include? "_spec" } \
.reject { |fn| fn.include? "vendor" }
commits = Hash[filenames.group_by { |e| e }.map {|k,v| [k,v.count] }]
csv_filename = "results.csv"
text = filenames.uniq.select {|fn| File.exist?(fn) }.map { |fn| "#{fn}, #{commits[fn]}, #{complexity(fn)}" }.join($/)
File.open(csv_filename,'w') { |f| f.write(text) }
`open #{csv_filename}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment