Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can rake stats be obtained in json?

I am planning to use the stats for my rails app for analysis.

I obtained the stats using

rake stats

All I obtained is a ascii formatted table. Is there a way to get this in JSON?

like image 892
avellable Avatar asked Nov 24 '25 02:11

avellable


1 Answers

Super-hacky and not in any way clever, but, here's how to turn a | separated table into json.

lines = `rake stats`.split("\n").collect{|l| l.split("|").collect(&:strip).reject(&:blank?)}.select{|l| l.size > 1}
hashes = []
headers = lines.shift
lines.each do |line|
  hash = {}
  headers.each_with_index do |header,i|
    hash[header] = line[i]
  end
  hashes << hash
end
hashes.to_json
like image 56
Max Williams Avatar answered Nov 26 '25 16:11

Max Williams