I have a file with data structured in this way…
http://pastie.org/1347044
So basically it’s
Country
Region
Resort
url
url
url
url
Resort
url
url
Country
Region
Resort
url
Resort
url
url
etc, the data is clearly structured and yaml like - but it’s not yaml I
feel. Anyway - I just wish to create active record objects out of it -
how would I go about processing that file - tips greatly appreciated?
On Dec 4, 2010, at 9:38 AM, bingo bob wrote:
etc, the data is clearly structured and yaml like - but it’s not
yaml I
feel. Anyway - I just wish to create active record objects out of it -
how would I go about processing that file - tips greatly appreciated?
I don’t have any specific code for you, but this is how I would attack
it:
- Split by lines.
- Loop through the lines, using the number of spaces at the beginning
of the line as a “level counter”.
- Whenever the level goes up or down, change to a new model –
Country, Region, Resort, Url. When the level goes up or down, keep
track of the preceding model object at the next lower level, as that
is your parent.
- At each line, create a new object of the current model, adding the
parent reference as appropriate.
Walter