YAML interpretation

K

Karan Rajput

I have one array in ruby as,

arr= [1, 2, '5', 'one', 'two', 'three', "4,6"]

as after doing arr.to_yaml, it prints as,

---
- 1
- 2
- "5"
- one
- two
- three
- "4,6"

This is my problem. It shows "4,6" as string (double-quoted) and
(one,two) are non-quoted which itself as string. I am passing this
string to some else database program which need clear distinction
between string and integer.

I require the result set as,

---
- 1
- 2
- "5"
- "one"
- "two"
- "three"
- "4,6"




Does yaml have any provision so that i can achieve the result set in
above consistent format?
 
R

Ryan Davis

I have one array in ruby as,

arr= [1, 2, '5', 'one', 'two', 'three', "4,6"]

as after doing arr.to_yaml, it prints as,

---
- 1
- 2
- "5"
- one
- two
- three
- "4,6"

This is my problem. It shows "4,6" as string (double-quoted) and
(one,two) are non-quoted which itself as string. I am passing this
string to some else database program which need clear distinction
between string and integer.

I require the result set as,

---
- 1
- 2
- "5"
- "one"
- "two"
- "three"
- "4,6"

Does yaml have any provision so that i can achieve the result set in
above consistent format?

yaml only provides the extra characters when the result would be
ambiguous. "- one" can't be seen as anything other than an array
element with the string one in it. "- 4,6" is ambiguous, so yaml
provides the extra quotes to disambiguate. I suggest you use a real
yaml parser instead of relying on regexps and duct tape. The spec is
well written and very clear about such things.
 
K

Karan Rajput

Ryan said:
yaml only provides the extra characters when the result would be
ambiguous. "- one" can't be seen as anything other than an array
element with the string one in it. "- 4,6" is ambiguous, so yaml
provides the extra quotes to disambiguate. I suggest you use a real
yaml parser instead of relying on regexps and duct tape. The spec is
well written and very clear about such things.

Hi Ryan,

Thanks for suggestion. But I am not clear about real yaml parser. As i
am using yaml package in ruby.

Could you please elaborate?
 
B

brabuhr

Hi Ryan,

Thanks for suggestion. But I am not clear about real yaml parser. As i
am using yaml package in ruby.

What is the other person's database program using to process the file?
("regexps and duct tape" or "a real yaml parser")
 
R

Ryan Davis

Hi Ryan,

Thanks for suggestion. But I am not clear about real yaml parser. As i
am using yaml package in ruby.

Could you please elaborate?

As you said: "I am passing this string to some else database program
which need clear distinction between string and integer"

SOMEONE is not using a real yaml parser... since yaml DOES have a
clear distinction between strings and integers.
 
K

Karan Rajput

unknown said:
What is the other person's database program using to process the file?
("regexps and duct tape" or "a real yaml parser")

Other database program expecting only the string, like,

---
- 1
- 2
- "5"
- "one"
- "two"
- "three"
- "4,6"

Its treats as the "string", not the "yaml string".
 
R

Ryan Davis

Other database program expecting only the string, like,

---
- 1
- 2
- "5"
- "one"
- "two"
- "three"
- "4,6"

Its treats as the "string", not the "yaml string".

then the database program is wrong. the yaml is correct. you should
fix what is wrong, not what is correct.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top