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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2010-Dec-04 15:00 UTC
Re: Processing a file of structured data of unknown origin
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: 1. Split by lines. 2. Loop through the lines, using the number of spaces at the beginning of the line as a "level counter". 3. 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. 4. At each line, create a new object of the current model, adding the parent reference as appropriate. Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.