[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

YAML iteration

aidy

2/28/2008 7:24:00 PM

Hi,

This is the YAML

test: tiscali1
url: http://tiscali3-test.v...
first_name: aidy
surname: smith
email: 'testautomated6@googlemail.com'
password: password
registration: KJHDF123

test: tiscali2
url: http://tiscali3-test.v...
first_name: aidy
surname: smith222
email: 'testautomated6@googlemail.com'
password: password
registration: KJHDF122

This is the code that is reading it:

<code>
def SmokeTest.create_from_yaml_file(filename)
data = YAML.load_file(filename)
obj = new(data['test'], data['url'])
obj.register(data['first_name'], data['surname'], data['email'],
data['password'], data['registration'])
obj

end


tiscali = SmokeTest.create_from_yaml_file('C:\test.yaml')
</code>

I would like to read the first YAML hash first, then the second and
any more, If the hash's are commneted out, i would like the data and
test to be ignored.

Aidy
1 Answer

Justin Collins

2/28/2008 8:45:00 PM

0

aidy wrote:
> Hi,
>
>
>
<snip>
> I would like to read the first YAML hash first, then the second and
> any more, If the hash's are commneted out, i would like the data and
> test to be ignored.
>
> Aidy
>

I believe you want YAML.load_documents:
http://ruby-doc.org/stdlib/libdoc/yaml/rdoc/classes/YAML.ht...
Not sure how comments work in YAML though.

-Justin