Created
August 23, 2012 06:11
-
-
Save irohiroki/3433271 to your computer and use it in GitHub Desktop.
Formatting metric_abc output of your Rails app
This file contains hidden or 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/env ruby | |
# | |
# usage: ./abc.rb | |
# | |
# Shows the total, average, and the worst 10 methods in the project. | |
def pt(line) | |
line[/(?<=: )\d+/].to_i | |
end | |
IO.popen("metric_abc `find app lib spec -name '*.rb'`"){|f| | |
n_line = 0 | |
total = 0 | |
n_worst = 10 | |
worst = [': 0'] * n_worst | |
while l = f.gets | |
n_line += 1 | |
total += pt(l) | |
worst[n_worst] = l | |
worst.sort!{|a,b| pt(b) - pt(a) } | |
end | |
print <<-END | |
Examined #{n_line} methods: | |
Total: #{total} / Ave. #{(total.to_f / n_line).round(2)} | |
Worst Ranking: | |
#{worst[0, 10].join} | |
END | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment