Skip to content

Instantly share code, notes, and snippets.

@monzou
Created October 17, 2011 10:10
Show Gist options
  • Save monzou/1292329 to your computer and use it in GitHub Desktop.
Save monzou/1292329 to your computer and use it in GitHub Desktop.
class RowParser
PATTERN = /^\s*([0-9]+)(\s*)(.*)\(cr=(\d+) r=(\d+) w=(\d+) time=(\d+)/
KEYS = [ :ROW, :INDENT, :OPERATION, :CR, :R, :W, :TIME ]
def parse(line)
tokens = line.scan(PATTERN)[0]
format(Hash[*([ KEYS, tokens ].transpose).flatten]) unless tokens.nil?
end
private
def format(h)
[ h[:ROW], h[:CR], h[:R], h[:W], h[:TIME], h[:INDENT].gsub(/\s/, "\t"), h[:OPERATION] ].join("\t")
end
end
open("row_trc.txt") do |f|
parser = RowParser.new
while l = f.gets
puts parser.parse(l)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment