avellable
avellable

Reputation: 1395

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?

Upvotes: 3

Views: 73

Answers (1)

Max Williams
Max Williams

Reputation: 32943

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

Upvotes: 2

Related Questions