Method: PostRunner::FlexiTable::Cell#to_s

Defined in:
lib/postrunner/FlexiTable.rb

#to_sObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/postrunner/FlexiTable.rb', line 67

def to_s
  s = @content.to_s
  width = get_attribute(:min_terminal_width)
  case get_attribute(:halign)
  when :left, nil
    s + ' ' * (width - s.length)
  when :right
    ' ' * (width - s.length) + s
  when :center
    w = width - s.length
    left_padding = w / 2
    right_padding = w / 2 + w % 2
    ' ' * left_padding + s + ' ' * right_padding
  else
    raise "Unknown alignment"
  end
end