Forum: Ruby on Rails Parsing key-value files

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
33f5c5c1e0731f5d14f87e66d22752d5?d=identicon&s=25 unknown (Guest)
on 2006-01-05 19:57
(Received via mailing list)
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
119af50160cabfe1fb6f2f05f5018c64?d=identicon&s=25 James Ludlow (Guest)
on 2006-01-07 13:37
(Received via mailing list)
On 1/5/06, vmalik@engmail.uwaterloo.ca <vmalik@engmail.uwaterloo.ca>
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
E48d29dc8fedb2878fa518d41cc63d88?d=identicon&s=25 Jan Prill (Guest)
on 2006-01-07 13:37
(Received via mailing list)
Hi, Vishal,

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

http://yaml4r.sourceforge.net/

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

Regards
Jan
E146c40bd510d1f1e455723485159670?d=identicon&s=25 Brian L. (Guest)
on 2006-01-07 13:37
(Received via mailing list)
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 Prill <JanPrill@blauton.de> wrote:
> Jan
> >I don't know how to parse these key-value files. Also, I was able to use Rails
> >
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> 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
bluczkie@andrew.cmu.edu, don't be concerned This is my new address,
but mail will be forwarded here indefinitely)
This topic is locked and can not be replied to.