Method: VMC::Spacing#tabular

Defined in:
lib/vmc/spacing.rb

#tabular(*rows) ⇒ Object



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
# File 'lib/vmc/spacing.rb', line 45

def tabular(*rows)
  spacings = []
  rows.each do |row|
    next unless row

    row.each.with_index do |col, i|
      next unless col

      width = text_width(col)

      if !spacings[i] || width > spacings[i]
        spacings[i] = width
      end
    end
  end

  columns = spacings.size
  rows.each do |row|
    next unless row

    row.each.with_index do |col, i|
      next unless col

      start_line justify(col, spacings[i])
      print "   " unless i + 1 == columns
    end

    line
  end
end