How can i easily parse a document which has this structure
description
some line of text
another line of text
more lines of text
quality
3 47 88 4 4 4 4
text: type 1
stats some funny stats
description
some line of text2
another line of text2
more lines of text2
quality
1 2 4 6 7
text: type 1
stats some funny stats
.
.
.
Ideally i would want an array of hash structures where each hash represents a ‘section’ of the document and probably should look like this:
{:description => “some line of text
another line of text
more lines of text”,
:quality => “3 47 88 4 4 4 4”,
:text =>type 1,
:stats => “some funny stats”}
You should look for the indicator lines (description, quality, text and stats) in a loop and fill the hash while processing the document line by line.
Another option would be to use regular expressions and parse the document at once, but you don’t really need regular expressions here, and if you’re not familiar with them, I’d have to recommend against regexes.
UPDATE: