lib/tailstrom/table.rb in tailstrom-0.0.3 vs lib/tailstrom/table.rb in tailstrom-0.0.4

- old
+ new

@@ -8,27 +8,31 @@ def print_row(*cols) cols.each_with_index do |col, i| col_schema = @schema[i] num_str = col ? num_with_delim(col) : '-' print ' ' if i > 0 - printf "%#{col_schema[:width]}s", num_str + align = col_schema[:align].to_s == 'left' ? '-' : nil + printf "%#{align}#{col_schema[:width]}s", num_str end - @out.puts + self.puts end def print_header border = head = '' @schema.each_with_index do |col, i| if i > 0 border += '-' head += ' ' - #border += '+' - #head += '|' end + align = col[:align].to_s == 'left' ? '-' : nil border += '-' * col[:width] - head += "%#{col[:width]}s" % col[:name] + head += "%#{align}#{col[:width]}s" % col[:name] end - @out.puts border, head, border + self.puts border, head, border + end + + def puts(*args) + @out.puts *args end private def num_with_delim(num) head, tail = num.to_s.split('.')