Class: Pvectl::Presenters::Capability
- Defined in:
- lib/pvectl/presenters/capability.rb
Overview
Presenter for node capabilities (QEMU CPU models, machine types).
Each Capability becomes one row regardless of kind. The DETAILS column adapts to the kind: CPU rows show vendor (and the “custom” marker when applicable), machine rows show the underlying machine family (q35/i440fx).
Instance Method Summary collapse
-
#columns ⇒ Array<String>
Returns column headers for table output.
-
#extra_columns ⇒ Array<String>
Returns extra columns for wide output (machine version, custom flag).
-
#extra_values(model, **_context) ⇒ Array<String>
Returns extra values for wide output.
-
#to_hash(model) ⇒ Hash{String => Object}
Converts capability to a hash for JSON/YAML output.
-
#to_row(model, **_context) ⇒ Array<String>
Converts capability to a row.
Methods inherited from Base
#tags_array, #tags_display, #template_display, #to_description, #to_wide_row, #uptime_human, #wide_columns
Instance Method Details
#columns ⇒ Array<String>
Returns column headers for table output.
23 24 25 |
# File 'lib/pvectl/presenters/capability.rb', line 23 def columns ["NODE", "KIND", "NAME", "DETAILS"] end |
#extra_columns ⇒ Array<String>
Returns extra columns for wide output (machine version, custom flag).
30 31 32 |
# File 'lib/pvectl/presenters/capability.rb', line 30 def extra_columns ["VERSION"] end |
#extra_values(model, **_context) ⇒ Array<String>
Returns extra values for wide output.
53 54 55 |
# File 'lib/pvectl/presenters/capability.rb', line 53 def extra_values(model, **_context) [model.version || "-"] end |
#to_hash(model) ⇒ Hash{String => Object}
Converts capability to a hash for JSON/YAML output.
Only the fields relevant to the kind are included; unset fields are omitted to keep the output compact and readable.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/pvectl/presenters/capability.rb', line 64 def to_hash(model) base = { "node" => model.node_name, "kind" => model.kind&.to_s, "name" => model.name } case model.kind when :cpu base["vendor"] = model.vendor if model.vendor base["custom"] = model.custom when :machine base["machine_type"] = model.machine_type if model.machine_type base["version"] = model.version if model.version base["changes"] = model.changes if model.changes end base end |
#to_row(model, **_context) ⇒ Array<String>
Converts capability to a row.
39 40 41 42 43 44 45 46 |
# File 'lib/pvectl/presenters/capability.rb', line 39 def to_row(model, **_context) [ model.node_name || "-", model.kind.to_s, model.name || "-", details(model) ] end |