how to think in Ruby way

H

H.J.LeoChen

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
 
R

Robert Klemme

H.J.LeoChen said:
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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top