how to think in Ruby way

Discussion in 'Ruby' started by H.J.LeoChen, Aug 12, 2004.

  1. H.J.LeoChen

    H.J.LeoChen Guest

    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
     
    H.J.LeoChen, Aug 12, 2004
    #1
    1. Advertising

  2. "H.J.LeoChen" <> schrieb im Newsbeitrag
    news:cffhr1$58e$...
    > 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
     
    Robert Klemme, Aug 12, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    612
  2. Replies:
    1
    Views:
    875
    Jack Klein
    Apr 13, 2005
  3. Replies:
    2
    Views:
    1,201
    Arved Sandstrom
    Apr 30, 2008
  4. Joe at CodeGear
    Replies:
    0
    Views:
    80
    Joe at CodeGear
    Feb 14, 2007
  5. David Mark
    Replies:
    17
    Views:
    242
    David Mark
    Mar 23, 2010
Loading...

Share This Page