Module: Chamomile::Align

Defined in:
lib/chamomile/styling/align.rb

Class Method Summary collapse

Class Method Details

.horizontal(lines, width, position) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/chamomile/styling/align.rb', line 6

def horizontal(lines, width, position)
  lines.map do |line|
    line_width = ANSI.printable_width(line)
    gap = width - line_width
    next line if gap <= 0

    left_pad = (gap * position).round
    right_pad = gap - left_pad
    "#{" " * left_pad}#{line}#{" " * right_pad}"
  end
end

.vertical(lines, height, position) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/chamomile/styling/align.rb', line 18

def vertical(lines, height, position)
  gap = height - lines.length
  return lines if gap <= 0

  top_pad = (gap * position).round
  bottom_pad = gap - top_pad

  result = []
  top_pad.times { result << "" }
  result.concat(lines)
  bottom_pad.times { result << "" }
  result
end