Class: Pvectl::Presenters::Capability

Inherits:
Base
  • Object
show all
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).

Examples:

Using with formatter

presenter = Capability.new
formatter = Formatters::Table.new
output = formatter.format(capabilities, presenter)

See Also:

Instance Method Summary collapse

Methods inherited from Base

#tags_array, #tags_display, #template_display, #to_description, #to_wide_row, #uptime_human, #wide_columns

Instance Method Details

#columnsArray<String>

Returns column headers for table output.

Returns:

  • (Array<String>)

    column headers



23
24
25
# File 'lib/pvectl/presenters/capability.rb', line 23

def columns
  ["NODE", "KIND", "NAME", "DETAILS"]
end

#extra_columnsArray<String>

Returns extra columns for wide output (machine version, custom flag).

Returns:

  • (Array<String>)

    extra columns



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.

Parameters:

Returns:

  • (Array<String>)


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.

Parameters:

Returns:

  • (Hash{String => Object})


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.

Parameters:

Returns:

  • (Array<String>)


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