36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/termline/table.rb', line 36
def builder data, header:true
return if Gem.win_platform?
return unless data.size > 0
table_from_array = true if data.first.class == Array
= false if table_from_array
if data.class.name == "ActiveRecord::Relation"
data = data.to_a.map(&:serializable_hash)
end
terminal_width = Style::WIDTH
cols = data.first.length + 1
col_width = (terminal_width / cols) - 1
return if col_width <= 0
separator = ('| ' << ('- ' * (col_width / 2)))
separator += (' ') if (col_width - separator.size).odd?
if
puts '| ' << data.first.keys.map { |key| key.to_s.upcase.ljust(col_width) }.join('| ')
end
puts separator * (cols - 1)
data.each_with_index do |row, index|
puts '| ' << row.values.map { |value| value.to_s.ljust(col_width) }.join('| ') unless table_from_array
puts '| ' << row.map { |value| value.to_s.ljust(col_width) }.join('| ') if table_from_array
end
puts separator * (cols - 1) unless
end
|