Class: CpuInspectCore::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/cpu_inspect_core/renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Renderer

Returns a new instance of Renderer.



5
6
7
8
# File 'lib/cpu_inspect_core/renderer.rb', line 5

def initialize(config)
  @idle_threshold = config.idle_threshold
  @bar_width      = config.bar_width
end

Instance Method Details

#render(cores_data) ⇒ Object

cores_data: Hash { “cpu0” => 12.5, “cpu1” => 45.2, … } Returns a multi-line String ready for puts.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cpu_inspect_core/renderer.rb', line 12

def render(cores_data)
  return 'No data collected yet.' if cores_data.nil? || cores_data.empty?

  normalized = cores_data.map { |name, pct| [name.to_s, pct] }
  label_width = normalized.map { |name, _| name.length }.max

  normalized
    .sort_by { |name, _| sort_key(name) }
    .map { |name, pct| format_line(name.ljust(label_width), pct) }
    .join("\n")
end