Class: Smt::Display

Inherits:
Object
  • Object
show all
Defined in:
lib/smt/display.rb

Constant Summary collapse

BOX =
{
  tl: "┌", tr: "┐", bl: "└", br: "┘",
  h: "─", v: "│",
  lm: "├", rm: "┤", tm: "┬", bm: "┴", cross: "┼"
}.freeze

Class Method Summary collapse

Class Method Details

.table(entries:, format:, time:) ⇒ Object



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