Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > how to think in Ruby way

Reply
Thread Tools

how to think in Ruby way

 
 
H.J.LeoChen
Guest
Posts: n/a
 
      08-12-2004
I'm new with developping with Ruby, When i deal with a problem ,always
manage it in C and then translate into Ruby.i always feel bad about it. now
i've got a task ,could you tell me how could manage it in Ruby way.
the task as followes:
here is a sample file contain some section of text like:

PARANAME=SMS
PARASTATUS=D2++R
PARACOUNT=2
PARAHEAD=mod-telsvr:
PARACMDNAME=DN
PARACMDVALUE=mdn=
PARACMDNAME=,smmopp=true
PARACMDVALUE=,smmtpp=true

it's a switcher command parser's configure file(a MS ini file)

and i want to translate it to the result like:
SMS+D++R=mod-telsvr:mdn=${DN},smmopp=true,smmtpp=true

steps as followes:
result=value of PARANAME + '+' + value of PARASTATUS + value of PARAHEAD
(all the variables are dealed as strings)
and then:
if the value of the string PARACMDNAME's in upper case,
result += PARACMDVALUE + ${PARACMDNAME}
otherwise,in lower case
result += PARACMDNAME + PARACMDVALUE


here is the original test file i wanna cope with:


PARANAME6=SMS
PARASTATUS6=D2++E
PARACOUNT6=2
PARAHEAD6=mod-telsvr:
PARACMDNAME60=DN
PARACMDVALUE60=mdn=
PARACMDNAME61=,smmopp=false
PARACMDVALUE61=,smmtpp=false

PARANAME7=ROAMING
PARASTATUS7=D0++R
PARACOUNT7=2
PARAHEAD7=mod-vlrlist:
PARACMDNAME70=DN
PARACMDVALUE70=mdn=
PARACMDNAME71=,roamflag=2
PARACMDVALUE71=,tempno=1

PARANAME8=ROAMING
PARASTATUS8=D0++E
PARACOUNT8=2
PARAHEAD8=mod-vlrlist:
PARACMDNAME80=DN
PARACMDVALUE80=mdn=
PARACMDNAME81=,roamflag=2


thanks


leo


 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      08-12-2004

"H.J.LeoChen" <(E-Mail Removed)> schrieb im Newsbeitrag
news:cffhr1$58e$(E-Mail Removed)...
> I'm new with developping with Ruby, When i deal with a problem ,always
> manage it in C and then translate into Ruby.i always feel bad about it.

now
> i've got a task ,could you tell me how could manage it in Ruby way.
> the task as followes:


IMHO there's not much to thinking this the Ruby Way(TM):

- parse values while reading the file
into an appropriate data structure
(Hash of Hashes comes to mind)

- iterate all configs and construct result strings

- process strings (output or whatever).

Regards

robert

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Need help: Is Quick-Union-Find the right solution to this problem (Now I don't think so and I think that topological sorting should be the way to go...?) ? aredo3604gif@yahoo.com C Programming 1 04-13-2005 12:48 AM
Need help: Is Quick-Union-Find the right solution to this problem (Now I don't think so and I think that topological sorting should be the way to go...?) ? aredo3604gif@yahoo.com C Programming 0 04-12-2005 05:06 PM
Think your Wireless Network is Secure? Think Again. Careers Computer Security 7 01-31-2004 07:04 AM
Think Off Brand Inks Are Just as Good in your Inkjet Printer - Think Again! John Horner Digital Photography 5 11-09-2003 09:38 PM



Advertisments