Class: SystemdMon::Formatters::StateTableFormatter

Inherits:
Base
  • Object
show all
Defined in:
lib/systemd_mon/formatters/state_table_formatter.rb

Instance Method Summary collapse

Methods inherited from Base

#as_html, #initialize

Constructor Details

This class inherits a constructor from SystemdMon::Formatters::Base

Instance Method Details

#as_textObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/systemd_mon/formatters/state_table_formatter.rb', line 4

def as_text
  table = render_table
  lengths = table.transpose.map { |v| v.map(&:length).max }

  full_width = lengths.inject(&:+) + (lengths.length * 3) + 1
  div = " " + ("-" * full_width) + "\n"
  s = div.dup
  table.each do |row|
    s << " | "
    row.each_with_index { |col, i|
      s << col.ljust(lengths[i]) + " | "
    }
    s << "\n" + div.dup
  end
  s
end