Class: Hashira::Report::Columns

Inherits:
Object
  • Object
show all
Defined in:
lib/hashira/report/columns.rb

Constant Summary collapse

CAP =
48
HEAD =
23
GAP =
"  "
NUMBER =
/\A-?\d+(?:\.\d+)?\z/

Instance Method Summary collapse

Constructor Details

#initialize(headers, rows, io: $stdout) ⇒ Columns

Returns a new instance of Columns.



9
10
11
12
# File 'lib/hashira/report/columns.rb', line 9

def initialize(headers, rows, io: $stdout)
  @headers, *@rows = [headers, *rows].map { |cells| cells.map { clip(it) } }
  @io = io
end

Instance Method Details

#bodyObject



20
# File 'lib/hashira/report/columns.rb', line 20

def body = @rows.each { @io.puts(line(it)) }

#headerObject



22
# File 'lib/hashira/report/columns.rb', line 22

def header = line(@headers)


14
15
16
17
18
# File 'lib/hashira/report/columns.rb', line 14

def print
  @io.puts(header)
  @io.puts(rule)
  body
end

#ruleObject



24
# File 'lib/hashira/report/columns.rb', line 24

def rule = "-" * [header, *@rows.map { line(it) }].map(&:length).max