11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/smt/display.rb', line 11
def self.table(entries:, format:, time:)
rows = entries.map do |entry|
{
emoji: entry[:emoji],
label: time.strftime(entry[:label]),
time: time.in_time_zone(entry[:time_zone]).strftime(format),
color: entry[:color].to_sym
}
end
emoji_w = 2
label_w = rows.map { |r| r[:label].length }.max
time_w = rows.map { |r| r[:time].length }.max
puts top_border(emoji_w, label_w, time_w)
rows.each_with_index do |row, i|
puts row_line(row, emoji_w, label_w, time_w)
puts mid_border(emoji_w, label_w, time_w) unless i == rows.length - 1
end
puts bottom_border(emoji_w, label_w, time_w)
end
|