Skip to content

Instantly share code, notes, and snippets.

@irohiroki
Created August 23, 2012 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irohiroki/3433271 to your computer and use it in GitHub Desktop.
Save irohiroki/3433271 to your computer and use it in GitHub Desktop.
Formatting metric_abc output of your Rails app
#!/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