Parsing key-value files

Hi,

I am very very new to both Ruby and Ruby on Rails. I have been given a
task to
create a web application, which is able to edit individual entries in a
key-value file. In other works, I would need to create an application
which can
parse a key-value file. Could someone guide me where I should start in a
case
like that? I was able to access and edit database table entries using
Rails, but
I don’t know how to parse these key-value files. Also, I was able to use
Rails
with a database because a tutorial showed me how to. I don’t know
anything about
Ruby. Will I have to write Ruby code in the controller of the
application to
parse a file? Is there an existing key-value file parsing method in
Ruby? Google
didn’t help much in answering these questions.

Thanks.

Vishal

On 1/5/06, [email protected] [email protected]
wrote:

I don’t know anything about Ruby.

If you’re going to create a webapp, it seems like you’d want to know
something about the language you’re using first. I’d suggest you read
at least the first several sections of Programming Ruby, either the
newer paper version or the older online version.

http://www.rubycentral.com/book/

– James

Hi, Vishal,

for your problem YAML might be the right choice:
http://www.ruby-doc.org/core/classes/YAML.html

of course you could parse simple key-value-pairs with regular
expressions…

Regards
Jan

If I were approaching this, I would probably avoid editing the
key-value file directly, and instead storing the key/value pairs in an
indexed database (if a flat-file was enough, then sqlite is probably
sufficient). Then provide import/export/merge(if meaningful) support
to/from the key/value file format. I don’t know what your keys and
values look like, but if it’s CSV or XML then ruby includes enough
library support to parse it out of the box. Yaml is pulled in by
rails, and doing your own parsing with regular expressions is dead
easy in ruby.

If it’s more complicated, then you might look into a recursive-descent
parsing framework. I don’t have much experience doing this in ruby,
but lemon and spirit are good choices in the c/c++ world and can do a
lot of the heavy lifting for you on real parsing tasks, especially if
performance matters.

Brian

On 1/5/06, Jan P. [email protected] wrote:

Jan

I don’t know how to parse these key-value files. Also, I was able to use Rails


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


The years ahead pick up their dark bags.
They move closer. There’s a slight rise in the silence

then nothing.

(If you’re receiving this in response to mail sent to
[email protected], don’t be concerned This is my new address,
but mail will be forwarded here indefinitely)