fork download
  1. items, chunks = [], []
  2.  
  3. DATA.each_line{|line|
  4. if line[0] == "["
  5. unless chunks.empty?
  6. # handle last chunk
  7. chunks[0].match(/\[(\w+) (\w+)\]/)
  8. items << Hash[$1, $2, *chunks.join.scan(/^(\w+)=(.+)$/).flatten]
  9. end
  10. # start new chunks
  11. chunks.clear; chunks << line
  12. else
  13. chunks << line
  14. end
  15. }
  16.  
  17. p items
  18.  
  19. __END__
  20. [WORLDCHAR c_horse_gray]
  21. CREATE=033ac420
  22. SERIAL=091600
  23. NAME=Gray Horse
  24. TIMER=0
  25. TAG.wexp_tot=019
  26. NPC=1
  27. P=1326,1341,7
  28. DIR=0
  29. FLAGS=048000000
  30. ACTION=070
  31. ACTARG1=07008f06c
  32. ACTARG2=06
  33. HITS=100
  34. STAM=50
  35. MANA=9
  36. FOOD=63
  37. STR=100
  38. INT=9
  39. DEX=50
  40. KARMA=1
  41. Parrying=441
  42. MagicResistance=253
  43. Tactics=379
  44. Taming=600
  45. Wrestling=343
  46. [EOF]
Success #stdin #stdout 0s 4760KB
stdin
Standard input is empty
stdout
[{"WORLDCHAR"=>"c_horse_gray", "CREATE"=>"033ac420", "SERIAL"=>"091600", "NAME"=>"Gray Horse", "TIMER"=>"0  ", "NPC"=>"1", "P"=>"1326,1341,7", "DIR"=>"0", "FLAGS"=>"048000000", "ACTION"=>"070", "ACTARG1"=>"07008f06c", "ACTARG2"=>"06", "HITS"=>"100 ", "STAM"=>"50  ", "MANA"=>"9   ", "FOOD"=>"63  ", "STR"=>"100  ", "INT"=>"9", "DEX"=>"50", "KARMA"=>"1   ", "Parrying"=>"441", "MagicResistance"=>"253", "Tactics"=>"379", "Taming"=>"600", "Wrestling"=>"343"}]