开发者

Parse dmidecode with ruby

开发者 https://www.devze.com 2023-01-16 20:13 出处:网络
Given the output of dmidecode Handle 0x0025, DMI type 13, 22 bytes BIOS Language Information Installable Languages: 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
Physica开发者_如何学Pythonl 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"} }


Hash[
    text.scan(/^(?:(\S.*?)\n((?: +.+\n?)+))/).map { |a,b|
        [a,
        Hash[
                b.scan(/  (.+?): (.+(?:(?:\n    .+))*)/)
            ]
        ]
    }
]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号