tags:

views:

39

answers:

1

Given the output of dmidecode

Handle 0x0025, DMI type 13, 22 bytes
BIOS Language Information
  Installable Languages: 1
    en|US|iso8859-1
  Currently Installed Language: en|US|iso8859-1

Handle 0x0026, DMI type 16, 15 bytes
Physical Memory Array
  Location: System Board Or Motherboard
  Use: System Memory
  Error Correction Type: Single-bit ECC 
  Maximum Capacity: 16 GB
  Error Information Handle: Not Provided
  Number Of Devices: 4

Now I'm looking for a regex/ ruby combo or something else to get a data structure similar to that

{ "BIOS Language Information" =>
    { "Installable Languages" =>  "1\n    en|US|iso8859-1", 
      "Currently Installed Language" => "en|US|iso8859-1"},
   "Physical Memory Array" =>
    { "Location" => "System Board Or Motherboard",
      "Use" => "System Memory"} }
+1  A: 
Hash[
    text.scan(/^(?:(\S.*?)\n((?: +.+\n?)+))/).map { |a,b|
        [a,
        Hash[
                b.scan(/  (.+?): (.+(?:(?:\n    .+))*)/)
            ]
        ]
    }
]
Nakilon
Many thanks Nakilon. But your code dosn't work. But I see what you want to say.I'm looking for a solution using Ragel. I'll post the results here soon.
zzeroo
I suppose, my solution doesn't work because it can be a little hard to paste original data to SO without changes. My solution is adapted to what I see in a question.
Nakilon