Class: Pvectl::Parsers::SmartText
- Inherits:
-
Object
- Object
- Pvectl::Parsers::SmartText
- Defined in:
- lib/pvectl/parsers/smart_text.rb
Overview
Parses smartctl text output (NVMe/SAS) into structured key-value pairs.
NVMe and SAS disks return SMART data as plain text from the Proxmox API (field text in GET /nodes/{node}/disks/smart). This parser extracts Key: Value lines into an Array of Hashes suitable for table display.
Class Method Summary collapse
-
.parse(text) ⇒ Array<Hash{String => String}>
Parses smartctl text output into structured attributes.
Class Method Details
.parse(text) ⇒ Array<Hash{String => String}>
Parses smartctl text output into structured attributes.
Splits each line on the first colon. Lines without a colon or without a non-empty value after the colon are skipped. Uses String#split instead of regex to avoid ReDoS risk.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pvectl/parsers/smart_text.rb', line 26 def self.parse(text) return [] if text.nil? || text.empty? text.each_line.filter_map { |line| key, value = line.strip.split(":", 2) next unless value key = key.strip value = value.strip next if key.empty? || value.empty? { "Attribute" => key, "Value" => value } } end |