> And make a new record for each line under Canada, with Canada of
> course being the key. How do I do this (syntax wise) with the YAML
> processor?
The easiest way of thinking about YAML syntax IMHO is to regards it as
a hash of keys and values.
So your example would not work, because the cities are not key =>
value pairs but are trying to be an array.
But the easy way is just ask Ruby how to turn this into YAML.
First make the ruby implementation of what you want, maybe like this:
data = { ''Canada'' => [ ''Vancouver'',
''Edmonton'', ''Calgary'',
''etc...'' ],
''Australia'' => [ ''sydney'',
''Melbourne'', ''Adelaide'',
''etc...'' ] }
And then go into IRB and ask Ruby:
# irb
irb(main):001:0> require ''yaml''
=> true
irb(main):002:0> data = { ''Canada'' => [
''Vancouver'', ''Edmonton'',
''Calgary'', ''etc...'' ],
''Australia'' => [ ''sydney'',
''Melbourne'',
''Adelaide'', ''etc...'' ] }
irb(main):003:0> puts data.to_yaml
---
Australia:
- Sydney
- Melbourne
- Adelaide
- etc...
Canada:
- Vancouver
- Edmonton
- Calgary
- etc...
And there you have it. Your YAML syntax nicely formatted for you.
Mikel
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---