Module Columnize
In: lib/columnize.rb
lib/version.rb
lib/columnize.rb

Module to format an Array as an Array of String aligned in columns.

Summary

Display a list of strings as a compact set of columns.

  For example, for a line width of 4 characters (arranged vertically):
       ['1', '2,', '3', '4'] => '1  3\n2  4\n'

   or arranged horizontally:
       ['1', '2,', '3', '4'] => '1  2\n3  4\n'

Each column is only as wide as necessary. By default, columns are separated by two spaces. Options are avalable for setting

  • the display width
  • the column separator
  • the line prefix
  • whether to ignore terminal codes in text size calculation
  • whether to left justify text instead of right justify

License

Columnize is copyright (C) 2007, 2008, 2009, 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>

All rights reserved. You can redistribute and/or modify it under the same terms as Ruby.

Adapted from the routine of the same name in Python +cmd.py+.

Methods

Constants

DEFAULT_OPTS = { :arrange_array => false, :arrange_vertical => true, :array_prefix => '', :array_suffix => '', :colsep => ' ', :displaywidth => 80, :lineprefix => '', :ljust => :auto, :term_adjust => false   When an option is not specified for the below keys, these are the defaults.
VERSION = '0.3.5'   The current version of this package
DEFAULT_OPTS = { :arrange_array => false, :arrange_vertical => true, :array_prefix => '', :array_suffix => '', :colsep => ' ', :displaywidth => 80, :lineprefix => '', :ljust => :auto, :term_adjust => false   When an option is not specified for the below keys, these are the defaults.

Public Instance methods

Return the length of String cell. If Boolean term_adjust is true, ignore terminal sequences in cell.

Return the length of String cell. If Boolean term_adjust is true, ignore terminal sequences in cell.

or arranged horizontally:

    ['1', '2,', '3', '4'] => '1  2\n3  4\n'

Each column is only as wide possible, no larger than +displaywidth’. If list is not an array, the empty string, ’’, is returned. By default, columns are separated by two spaces - one was not legible enough. Set colsep to adjust the string separate columns. If arrange_vertical is set false, consecutive items will go across, left to right, top to bottom.

or arranged horizontally:

    ['1', '2,', '3', '4'] => '1  2\n3  4\n'

Each column is only as wide possible, no larger than +displaywidth’. If list is not an array, the empty string, ’’, is returned. By default, columns are separated by two spaces - one was not legible enough. Set colsep to adjust the string separate columns. If arrange_vertical is set false, consecutive items will go across, left to right, top to bottom.

Options parsing routine for Columnize::columnize. In the preferred newer style, args is either a hash where each key is one of the option names:

arrange_vertical
Arrange list vertically rather than horizontally. This is the default
colsep
String used to separate columns
displaywidth
Maximum width of each line
ljust
Boolean or +:auto+: Left-justify fields in a column? The default is true. If

the :auto, then right-justify if every element of the data is a kind of Numeric.

lineprefix
String: string to prepend to each line. The default is ’’.

In the older style positional arguments are used and the positions are in the order: displaywidth, colsep, arrange_vertical, ljust, and lineprefix.

Options parsing routine for Columnize::columnize. In the preferred newer style, args is either a hash where each key is one of the option names:

arrange_vertical
Arrange list vertically rather than horizontally. This is the default
colsep
String used to separate columns
displaywidth
Maximum width of each line
ljust
Boolean or +:auto+: Left-justify fields in a column? The default is true. If

the :auto, then right-justify if every element of the data is a kind of Numeric.

lineprefix
String: string to prepend to each line. The default is ’’.

In the older style positional arguments are used and the positions are in the order: displaywidth, colsep, arrange_vertical, ljust, and lineprefix.

[Validate]