代码之家  ›  专栏  ›  技术社区  ›  zzeroo

用ruby解析dmidecode

  •  1
  • zzeroo  · 技术社区  · 14 年前

    给定的输出 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
    

    现在我正在寻找一个regex/ruby组合或其他东西来获得类似的数据结构

    { "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 回复  |  直到 14 年前
        1
  •  1
  •   Nakilon earlonrails    14 年前
    Hash[
        text.scan(/^(?:(\S.*?)\n((?: +.+\n?)+))/).map { |a,b|
            [a,
            Hash[
                    b.scan(/  (.+?): (.+(?:(?:\n    .+))*)/)
                ]
            ]
        }
    ]