columnize-0.9.0/0000755000004100000410000000000012443740135013560 5ustar www-datawww-datacolumnize-0.9.0/Rakefile0000644000004100000410000000450112443740135015225 0ustar www-datawww-data#!/usr/bin/env rake # -*- Ruby -*- require 'rubygems' require 'fileutils' ROOT_DIR = File.dirname(__FILE__) Gemspec_filename = 'columnize.gemspec' require File.join %W(#{ROOT_DIR} lib columnize version) def gemspec @gemspec ||= eval(File.read(Gemspec_filename), binding, Gemspec_filename) end require 'rubygems/package_task' desc "Build the gem" task :package=>:gem task :gem=>:gemspec do Dir.chdir(ROOT_DIR) do sh "gem build columnize.gemspec" FileUtils.mkdir_p 'pkg' FileUtils.mv gemspec.file_name, 'pkg' end end desc "Install the gem locally" task :install => :gem do Dir.chdir(ROOT_DIR) do sh %{gem install --local pkg/#{gemspec.file_name}} end end require 'rake/testtask' desc "Test everything." Rake::TestTask.new(:test) do |t| t.libs << './lib' t.test_files = FileList['test/test-*.rb'] t.verbose = true end task :test => :lib desc "same as test" task :check => :test desc "same as test" task :columnize => :test desc 'Create a GNU-style ChangeLog via git2cl' task :ChangeLog do system('git log --pretty --numstat --summary | git2cl > ChangeLog') end task :default => [:test] desc 'Create a GNU-style ChangeLog via git2cl' task :ChangeLog do system('git log --pretty --numstat --summary | git2cl > ChangeLog') end desc "Generate the gemspec" task :generate do puts gemspec.to_ruby end desc "Validate the gemspec" task :gemspec do gemspec.validate end # --------- RDoc Documentation ------ require 'rdoc/task' desc "Generate rdoc documentation" Rake::RDocTask.new("rdoc") do |rdoc| rdoc.rdoc_dir = 'doc' rdoc.title = "Columnize #{Columnize::VERSION} Documentation" # Make the README file the start page for the generated html rdoc.options += %w(--main README.md) rdoc.rdoc_files.include('lib/*.rb', 'README.md', 'COPYING') end desc "Same as rdoc" task :doc => :rdoc task :clobber_package do FileUtils.rm_rf File.join(ROOT_DIR, 'pkg') end task :clobber_rdoc do FileUtils.rm_rf File.join(ROOT_DIR, 'doc') end desc 'Remove residue from running patch' task :rm_patch_residue do FileUtils.rm_rf Dir.glob('**/*.{rej,orig}'), :verbose => true end desc 'Remove ~ backup files' task :rm_tilde_backups do FileUtils.rm_rf Dir.glob('**/*~'), :verbose => true end desc 'Remove built files' task :clean => [:clobber_package, :clobber_rdoc, :rm_patch_residue, :rm_tilde_backups] columnize-0.9.0/Gemfile.lock0000644000004100000410000000035512443740135016005 0ustar www-datawww-dataPATH remote: . specs: columnize (0.8.9) GEM remote: https://rubygems.org/ specs: json (1.8.0) rake (10.1.0) rdoc (4.0.1) json (~> 1.4) PLATFORMS ruby DEPENDENCIES columnize! rake (~> 10.1.0) rdoc columnize-0.9.0/Gemfile0000644000004100000410000000004712443740135015054 0ustar www-datawww-datasource 'https://rubygems.org' gemspec columnize-0.9.0/THANKS0000644000004100000410000000040012443740135014465 0ustar www-datawww-dataI am indebted to: Mark Moseley: the initial port from 1.8 to 1.9 Martin Davis: how to extend into Array classes and set options from there David Rodríguez de Dios: Miscellaneous portability fixes and doggedness to get out a new release columnize-0.9.0/NEWS0000644000004100000410000000276112443740135014265 0ustar www-datawww-data0.9.0 Dec 5, 2014 - Early gecko 0.8.9 Apr 19, 2014 - Add columnize method to Array class and a place to set its default options - Add option :colfmt to allow a format specifier to use (e.g. '%02d') in stringifying list items - Add option linesuffix (default is "\n") - When using arrange_array each line now has trailing "," 0.3.6 Dec 17, 2011 - rename version.rb columnize/version.rb so as not to conflict with another package called version - Administrivia - shorten gemcutter description 0.3.5 Nov 24, 2011 - Handle situation where an array element is larger than the display width. 0.3.4 July 4, 2011 - Change to Ruby License - Add option 'term_adjust' to ignore terminal sequences in text - Add :ljust => :auto to decide whether or not to automatically left or right justify. When passing a hash parameter, the default is :auto. 0.3.3 June 12, 2011 Fleetwood release - More general but simpler inteface using an options hash. Compatibility is maintaind though. 0.3.2 - Mostly Administrivia. * Add .gemspec, correct description field and add a summary. * Add Columnize::VERSION * Simplify Rakefile * Add stub Makefiles 0.3.1 (01-07-26) - Correct for Ruby 1.9 (Mark Moseley) - add optional lineprefix parameter 0.3.0 (01-10-09) - Sam Woodward Release - Fix bad bug in arranging horizontally 0.2.1 (12-31-08) - Add ability to run columns horizontally 0.2 - Minor - get rid of hacky $0 test 0.1 - Initial release of Columnize, a module to print an Array in column-sorted order columnize-0.9.0/.travis.yml0000644000004100000410000000015112443740135015666 0ustar www-datawww-datalanguage: ruby rvm: - 1.8.7 - 1.9.3 - 2.0.0 - 2.1.5 matrix: allow_failures: - rvm: ruby-head columnize-0.9.0/lib/0000755000004100000410000000000012443740135014326 5ustar www-datawww-datacolumnize-0.9.0/lib/columnize.rb0000644000004100000410000001113312443740135016657 0ustar www-datawww-data# Module to format an Array into a single string with embedded # newlines, On printing the string, the columns are aligned. # # == Summary # # Return a string from an array with embedded newlines formatted so # that when printed the columns are aligned. # See below for examples and options to the main method +columnize+. # # # == License # # Columnize is copyright (C) 2007-2011, 2013 Rocky Bernstein # # # All rights reserved. You can redistribute and/or modify it under # the same terms as Ruby. # # Also available in Python (columnize), and Perl (Array::Columnize) module Columnize # Pull in the rest of my pieces ROOT_DIR = File.dirname(__FILE__) %w(opts columnize version).each do |submod| require File.join %W(#{ROOT_DIR} columnize #{submod}) end # Add +columnize_opts+ instance variable to classes that mix in this module. The type should be a kind of hash in file +columnize/opts+. attr_accessor :columnize_opts # Columnize.columize([args]) => String # # Return a string from an array with embedded newlines formatted so # that when printed the columns are aligned. # # For example, for a line width of 4 characters (arranged vertically): # a = (1..4).to_a # Columnize.columnize(a) => '1 3\n2 4\n' # # Alternatively: # a.columnize => '1 3\n2 4\n' # # Arranged horizontally: # a.columnize(:arrange_vertical => false) => # ['1', '2,', '3', '4'] => '1 2\n3 4\n' # # Formatted as an array using format specifier '%02d': # puts (1..10).to_a.columnize(:arrange_array => true, :colfmt => '%02d', # :displaywidth => 10) => # [01, 02, # 03, 04, # 05, 06, # 07, 08, # 09, 10, # ] # # Each column is only as wide as necessary. By default, columns are # separated by two spaces. Options are available for setting # * the line display width # * a column separator # * a line prefix # * a line suffix # * A format specify for formatting each item each array item to a string # * whether to ignore terminal codes in text size calculation # * whether to left justify text instead of right justify # * whether to format as an array - with surrounding [] and # separating ', ' def self.columnize(*args) list = args.shift opts = parse_columnize_options(args) Columnizer.new(list, opts).columnize end # Adds columnize_opts to the singleton level of included class def self.included(base) # screw class variables, we'll use an instance variable on the class singleton class << base attr_accessor :columnize_opts end base.columnize_opts = DEFAULT_OPTS.dup end def columnize(*args) return Columnize.columnize(*args) if args.length > 1 opts = args.empty? ? {} : args.pop @columnize_opts ||= self.class.columnize_opts.dup @columnizer ||= Columnizer.new(self, @columnize_opts) # make sure that any changes to list or opts get passed to columnizer @columnizer.list = self unless @columnizer.list == self @columnizer.opts = @columnize_opts.merge(opts) unless @columnizer.opts == @columnize_opts and opts.empty? @columnizer.columnize end end # Mix Columnize into Array Array.send :include, Columnize # Demo this sucker if __FILE__ == $0 # include Columnize a = (1..80).to_a puts a.columnize :arrange_array => true puts '=' * 50 b = (1..10).to_a puts b.columnize(:displaywidth => 10) puts '-' * 50 puts b.columnize(:arrange_array => true, :colfmt => '%02d', :displaywidth => 10) [[4, 4], [4, 7], [100, 80]].each do |width, num| data = (1..num).map{|i| i } [[false, 'horizontal'], [true, 'vertical']].each do |bool, dir| puts "Width: #{width}, direction: #{dir}" print Columnize.columnize(data, :displaywidth => width, :colsep => ' ', :arrange_vertical => bool, :ljust => :auto) end end puts Columnize.columnize(5) puts Columnize.columnize([]) puts Columnize.columnize(["a", 2, "c"], :displaywidth =>10, :colsep => ', ') puts Columnize.columnize(["oneitem"]) puts Columnize.columnize(["one", "two", "three"]) data = ["one", "two", "three", "for", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen", "twenty", "twentyone", "twentytwo", "twentythree", "twentyfour", "twentyfive","twentysix", "twentyseven"] puts Columnize.columnize(data) puts Columnize.columnize(data, 80, ' ', false) end columnize-0.9.0/lib/Makefile0000644000004100000410000000044612443740135015772 0ustar www-datawww-data# Whatever it is you want to do, it should be handled by the main # (parent) Makefile. So reissue make from there. PHONY=check all #: Default target - the parent's testing or "check" target all: check #: Whatever it is you want to do, it should be handled by the parent %: $(MAKE) -C .. $@ columnize-0.9.0/lib/columnize/0000755000004100000410000000000012443740135016333 5ustar www-datawww-datacolumnize-0.9.0/lib/columnize/opts.rb0000644000004100000410000000236012443740135017646 0ustar www-datawww-datamodule Columnize computed_displaywidth = (ENV['COLUMNS'] || '80').to_i computed_displaywidth = 80 unless computed_displaywidth >= 10 # When an option is not specified for the below keys, these are the defaults. DEFAULT_OPTS = { :arrange_array => false, :arrange_vertical => true, :array_prefix => '', :array_suffix => '', :colfmt => nil, :colsep => ' ', :displaywidth => computed_displaywidth, :line_prefix => '', :line_suffix => '', :ljust => :auto, :term_adjust => false } # Options parsing routine for Columnize::columnize. In the preferred # newer style, +args+ is a hash where each key is one of the option names. # # In the older style positional arguments are used and the positions # are in the order: +displaywidth+, +colsep+, +arrange_vertical+, # +ljust+, and +line_prefix+. def self.parse_columnize_options(args) if 1 == args.size && args[0].kind_of?(Hash) # explicitly passed as a hash args[0] elsif !args.empty? # passed as ugly positional parameters. Hash[args.zip([:displaywidth, :colsep, :arrange_vertical, :ljust, :line_prefix]).map(&:reverse)] else {} end end end columnize-0.9.0/lib/columnize/columnize.rb0000644000004100000410000001362712443740135020676 0ustar www-datawww-data# Copyright (C) 2007-2011, 2013 Rocky Bernstein # # # Part of Columnize to format in either direction module Columnize class Columnizer ARRANGE_ARRAY_OPTS = {:array_prefix => '[', :line_prefix => ' ', :line_suffix => ',', :array_suffix => ']', :colsep => ', ', :arrange_vertical => false} OLD_AND_NEW_KEYS = {:lineprefix => :line_prefix, :linesuffix => :line_suffix} # TODO: change colfmt to cell_format; change colsep to something else ATTRS = [:arrange_vertical, :array_prefix, :array_suffix, :line_prefix, :line_suffix, :colfmt, :colsep, :displaywidth, :ljust] attr_reader :list, :opts def initialize(list=[], opts={}) self.list = list self.opts = DEFAULT_OPTS.merge(opts) end def list=(list) @list = list if @list.is_a? Array @short_circuit = @list.empty? ? "\n" : nil else @short_circuit = '' @list = [] end end # TODO: freeze @opts def opts=(opts) @opts = opts OLD_AND_NEW_KEYS.each {|old, new| @opts[new] = @opts.delete(old) if @opts.keys.include?(old) and !@opts.keys.include?(new) } @opts.merge!(ARRANGE_ARRAY_OPTS) if @opts[:arrange_array] set_attrs_from_opts end def update_opts(opts) self.opts = @opts.merge(opts) end def columnize return @short_circuit if @short_circuit rows, colwidths = min_rows_and_colwidths ncols = colwidths.length justify = lambda {|t, c| @ljust ? t.ljust(colwidths[c]) : t.rjust(colwidths[c]) } textify = lambda do |row| row.map!.with_index(&justify) unless ncols == 1 && @ljust "#{@line_prefix}#{row.join(@colsep)}#{@line_suffix}" end text = rows.map(&textify) text.first.sub!(/^#{@line_prefix}/, @array_prefix) unless @array_prefix.empty? text.last.sub!(/#{@line_suffix}$/, @array_suffix) unless @array_suffix.empty? text.join("\n") # + "\n" # if we want extra separation end # TODO: make this a method, rather than a function (?) # compute the smallest number of rows and the max widths for each column def min_rows_and_colwidths list = @list.map(&@stringify) cell_widths = list.map(&@term_adjuster).map(&:size) # Set default arrangement: one atom per row cell_width_max = cell_widths.max result = [arrange_by_row(list, list.size, 1), [cell_width_max]] # If any atom > @displaywidth, stop and use one atom per row. return result if cell_width_max > @displaywidth # For horizontal arrangement, we want to *maximize* the number # of columns. Thus the candidate number of rows (+sizes+) starts # at the minumum number of rows, 1, and increases. # For vertical arrangement, we want to *minimize* the number of # rows. So here the candidate number of columns (+sizes+) starts # at the maximum number of columns, list.length, and # decreases. Also the roles of columns and rows are reversed # from horizontal arrangement. # Loop from most compact arrangement to least compact, stopping # at the first successful packing. The below code is tricky, # but very cool. # # FIXME: In the below code could be DRY'd. (The duplication got # introduced when I revised the code - rocky) if @arrange_vertical (1..list.length).each do |size| other_size = (list.size + size - 1) / size colwidths = arrange_by_row(cell_widths, other_size, size).map(&:max) totwidth = colwidths.inject(&:+) + ((colwidths.length-1) * @colsep.length) return [arrange_by_column(list, other_size, size), colwidths] if totwidth <= @displaywidth end else list.length.downto(1).each do |size| other_size = (list.size + size - 1) / size colwidths = arrange_by_column(cell_widths, other_size, size).map(&:max) totwidth = colwidths.inject(&:+) + ((colwidths.length-1) * @colsep.length) return [arrange_by_row(list, other_size, size), colwidths] if totwidth <= @displaywidth end end result end # Given +list+, +ncols+, +nrows+, arrange the one-dimensional # array into a 2-dimensional lists of lists organized by rows. # # In either horizontal or vertical arrangement, we will need to # access this for the list data or for the width # information. # # Here is an example: # arrange_by_row((1..5).to_a, 3, 2) => # [[1,2], [3,4], [5]], def arrange_by_row(list, nrows, ncols) (0...nrows).map {|r| list[r*ncols, ncols] }.compact end # Given +list+, +ncols+, +nrows+, arrange the one-dimensional # array into a 2-dimensional lists of lists organized by columns. # # In either horizontal or vertical arrangement, we will need to # access this for the list data or for the width # information. # # Here is an example: # arrange_by_column((1..5).to_a, 2, 3) => # [[1,3,5], [2,4]] def arrange_by_column(list, nrows, ncols) (0...ncols).map do |i| (0..nrows-1).inject([]) do |row, j| k = i + (j * ncols) k < list.length ? row << list[k] : row end end end def set_attrs_from_opts ATTRS.each {|attr| self.instance_variable_set "@#{attr}", @opts[attr] } @ljust = !@list.all? {|datum| datum.kind_of?(Numeric)} if @ljust == :auto @displaywidth -= @line_prefix.length @displaywidth = @line_prefix.length + 4 if @displaywidth < 4 @stringify = @colfmt ? lambda {|li| @colfmt % li } : lambda {|li| li.to_s } @term_adjuster = @opts[:term_adjust] ? lambda {|c| c.gsub(/\e\[.*?m/, '') } : lambda {|c| c } end end end # Demo if __FILE__ == $0 Columnize::DEFAULT_OPTS = {:line_prefix => '', :displaywidth => 80} puts Columnize::Columnizer.new.arrange_by_row((1..5).to_a, 2, 3).inspect puts Columnize::Columnizer.new.arrange_by_column((1..5).to_a, 2, 3).inspect end columnize-0.9.0/lib/columnize/version.rb0000644000004100000410000000036112443740135020345 0ustar www-datawww-data# Sets constant Columnize::VERSION, the version number of # this package. It is used in Gem creation but can also be consulted after # require'ing 'columnize'. module Columnize # The current version of this package VERSION = '0.9.0' end columnize-0.9.0/lib/columnize/Makefile0000644000004100000410000000045712443740135020001 0ustar www-datawww-data# Whatever it is you want to do, it should be handled by the main # (parent) Makefile. So reissue make from there. PHONY=check all #: Default target - the parent's testing or "check" target all: check true #: Whatever it is you want to do, it should be handled by the parent %: $(MAKE) -C ../.. $@ columnize-0.9.0/metadata.yml0000644000004100000410000000501512443740135016064 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: columnize version: !ruby/object:Gem::Version version: 0.9.0 prerelease: platform: ruby authors: - Rocky Bernstein autorequire: bindir: bin cert_chain: [] date: 2014-12-05 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rdoc requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 10.1.0 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 10.1.0 description: ! ' In showing a long lists, sometimes one would prefer to see the value arranged aligned in columns. Some examples include listing methods of an object or debugger commands. See Examples in the rdoc documentation for examples. ' email: rockyb@rubyforge.net executables: [] extensions: [] extra_rdoc_files: - README.md - lib/columnize.rb - COPYING - THANKS files: - .gitignore - .travis.yml - AUTHORS - COPYING - ChangeLog - Gemfile - Gemfile.lock - Makefile - NEWS - README.md - Rakefile - THANKS - columnize.gemspec - lib/Makefile - lib/columnize.rb - lib/columnize/Makefile - lib/columnize/columnize.rb - lib/columnize/opts.rb - lib/columnize/version.rb - test/test-columnize-array.rb - test/test-columnize.rb - test/test-columnizer.rb - test/test-hashparm.rb - test/test-issue3.rb - test/test-min_rows_and_colwidths.rb homepage: https://github.com/rocky/columnize licenses: - Ruby - GPL2 post_install_message: rdoc_options: - --main - README - --title - Columnize 0.9.0 Documentation require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 1.8.2 required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: columnize rubygems_version: 1.8.23 signing_key: specification_version: 3 summary: Module to format an Array as an Array of String aligned in columns test_files: [] columnize-0.9.0/test/0000755000004100000410000000000012443740135014537 5ustar www-datawww-datacolumnize-0.9.0/test/test-issue3.rb0000755000004100000410000000177412443740135017270 0ustar www-datawww-data#!/usr/bin/env ruby require 'test/unit' # Test of Columnize module for github issue #3 class TestIssue3 < Test::Unit::TestCase @@TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib') require File.join(@@TOP_SRC_DIR, 'columnize.rb') # test columnize def test_long_column data = ["what's", "upppppppppppppppppp"] data.columnize_opts = Columnize::DEFAULT_OPTS.merge :displaywidth => 7, :arrange_vertical => false assert_equal("what's\nupppppppppppppppppp", data.columnize) assert_equal("what's\nupppppppppppppppppp", data.columnize(:arrange_vertical => true)) end def test_long_column_with_ljust data = ["whaaaaaat's", "up"] data.columnize_opts = Columnize::DEFAULT_OPTS.merge :displaywidth => 7, :arrange_vertical => false, :ljust => true assert_equal("whaaaaaat's\nup", data.columnize) assert_equal("whaaaaaat's\n up", data.columnize(:ljust => false)) assert_equal("whaaaaaat's\nup", data.columnize(:arrange_vertical => true)) end end columnize-0.9.0/test/test-min_rows_and_colwidths.rb0000755000004100000410000000501612443740135022605 0ustar www-datawww-data#!/usr/bin/env ruby require 'test/unit' # Test of Columnize#min_rows_and_colwidths class TestComputeRowsAndColwidths < Test::Unit::TestCase # Ruby 1.8 form of require_relative TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib') require File.join(TOP_SRC_DIR, 'columnize.rb') VOPTS = Columnize::DEFAULT_OPTS.merge(:displaywidth => 80) HOPTS = VOPTS.merge(:arrange_vertical => false) def min_rows_and_colwidths(list, opts) Columnize::Columnizer.new(list, opts).min_rows_and_colwidths end def test_colwidths data = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen", "twenty", "twentyone", "twentytwo", "twentythree", "twentyfour", "twentyfive","twentysix", "twentyseven"] [['horizontal', HOPTS, [10, 9, 11, 9, 11, 10], 5, 6], ['vertical' , VOPTS, [5, 5, 6, 8, 9, 11, 11], 4, 7]].each do |direction, opts, expect_colwidths, expect_rows, expect_cols| rows, colwidths = min_rows_and_colwidths(data, opts) assert_equal(expect_colwidths, colwidths, "colwidths - #{direction}") assert_equal(expect_rows, rows.length, "number of rows - #{direction}") assert_equal(expect_cols, rows.first.length, "number of cols - #{direction}") end end def test_horizontal_vs_vertical data = (0..54).map{|i| i.to_s} [['horizontal', HOPTS.merge(:displaywidth => 39), [2,2,2,2,2,2,2,2,2,2]], ['vertical' , VOPTS.merge(:displaywidth => 39), [1,2,2,2,2,2,2,2,2,2]]].each do |direction, opts, expect| rows, colwidths = min_rows_and_colwidths(data, opts) assert_equal(expect, colwidths, "colwidths #{direction}") assert_equal(6, rows.length, "number of rows - #{direction}") assert_equal(10, rows.first.length, "number of cols - #{direction}") end end def test_displaywidth_smaller_than_largest_atom data = ['a' * 100, 'b', 'c', 'd', 'e'] [['horizontal', HOPTS], ['vertical' , VOPTS]].each do |direction, opts| rows, colwidths = min_rows_and_colwidths(data, opts) assert_equal([100], colwidths, "colwidths #{direction}") assert_equal(5, rows.length, "number of rows - #{direction}") assert_equal(1, rows.first.length, "number of cols - #{direction}") end end end columnize-0.9.0/test/test-columnize-array.rb0000755000004100000410000000327712443740135021176 0ustar www-datawww-data#!/usr/bin/env ruby require 'test/unit' # Test of Columnize module class TestColumnizeArray < Test::Unit::TestCase # Ruby 1.8 form of require_relative TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib') ENV['COLUMNS'] = '80' require File.join(TOP_SRC_DIR, 'columnize.rb') # test columnize def test_arrange_array data = (1..80).to_a expect = "[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,\n" + " 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,\n" + " 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,\n" + " 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80]" assert_equal(expect, data.columnize(:arrange_array => true, :displaywidth => 80), "columnize_opts -> arrange_array") end def test_displaywidth expect = "1 5 9\n" + "2 6 10\n" + "3 7\n" + "4 8" data = (1..10).to_a assert_equal(expect, data.columnize(:displaywidth => 10), "displaywidth") end def test_colfmt expect = "[01, 02,\n" + " 03, 04,\n" + " 05, 06,\n" + " 07, 08,\n" + " 09, 10]" data = (1..10).to_a assert_equal(expect, data.columnize(:arrange_array => true, :colfmt => '%02d', :displaywidth => 10), "arrange_array, colfmt, displaywidth") end def test_backwards_compatiblity foo = [] data = (1..11).to_a expect = " 1 2 3\n 4 5 6\n 7 8 9\n10 11" assert_equal expect, foo.columnize(data, :displaywidth => 10, :arrange_vertical => false) end end columnize-0.9.0/test/test-columnize.rb0000755000004100000410000000621012443740135020050 0ustar www-datawww-data#!/usr/bin/env ruby require 'test/unit' # Test of Columnize module class TestColumnize < Test::Unit::TestCase # Ruby 1.8 form of require_relative TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib') require File.join(TOP_SRC_DIR, 'columnize.rb') # test columnize def test_basic assert_equal("1, 2, 3", Columnize::columnize([1, 2, 3], 10, ', ')) assert_equal("", Columnize::columnize(5)) assert_equal("1 3\n2 4", Columnize::columnize(['1', '2', '3', '4'], 4)) assert_equal("1 2\n3 4", Columnize::columnize(['1', '2', '3', '4'], 4, ' ', false)) assert_equal("\n", Columnize::columnize([])) assert_equal("oneitem", Columnize::columnize(["oneitem"])) data = (0..54).map{|i| i.to_s} assert_equal( "0, 6, 12, 18, 24, 30, 36, 42, 48, 54\n" + "1, 7, 13, 19, 25, 31, 37, 43, 49\n" + "2, 8, 14, 20, 26, 32, 38, 44, 50\n" + "3, 9, 15, 21, 27, 33, 39, 45, 51\n" + "4, 10, 16, 22, 28, 34, 40, 46, 52\n" + "5, 11, 17, 23, 29, 35, 41, 47, 53", Columnize::columnize(data, 39, ', ', true, false)) assert_equal( " 0, 1, 2, 3, 4, 5, 6, 7, 8, 9\n" + "10, 11, 12, 13, 14, 15, 16, 17, 18, 19\n" + "20, 21, 22, 23, 24, 25, 26, 27, 28, 29\n" + "30, 31, 32, 33, 34, 35, 36, 37, 38, 39\n" + "40, 41, 42, 43, 44, 45, 46, 47, 48, 49\n" + "50, 51, 52, 53, 54", Columnize::columnize(data, 39, ', ', false, false)) assert_equal( " 0, 1, 2, 3, 4, 5, 6, 7, 8\n" + " 9, 10, 11, 12, 13, 14, 15, 16, 17\n" + " 18, 19, 20, 21, 22, 23, 24, 25, 26\n" + " 27, 28, 29, 30, 31, 32, 33, 34, 35\n" + " 36, 37, 38, 39, 40, 41, 42, 43, 44\n" + " 45, 46, 47, 48, 49, 50, 51, 52, 53\n" + " 54", Columnize::columnize(data, 39, ', ', false, false, ' ')) data = ["one", "two", "three", "for", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen", "twenty", "twentyone", "twentytwo", "twentythree", "twentyfour", "twentyfive","twentysix", "twentyseven"] assert_equal( "one two three for five six \n" + "seven eight nine ten eleven twelve \n" + "thirteen fourteen fifteen sixteen seventeen eightteen \n" + "nineteen twenty twentyone twentytwo twentythree twentyfour\n" + "twentyfive twentysix twentyseven", Columnize::columnize(data, 80, ' ', false)) assert_equal( "one five nine thirteen seventeen twentyone twentyfive \n" + "two six ten fourteen eightteen twentytwo twentysix \n" + "three seven eleven fifteen nineteen twentythree twentyseven\n" + "for eight twelve sixteen twenty twentyfour ", Columnize::columnize(data, 80)) end end columnize-0.9.0/test/test-hashparm.rb0000755000004100000410000000340712443740135017653 0ustar www-datawww-data#!/usr/bin/env ruby require 'test/unit' # Test of Columnize module class TestHashFormat < Test::Unit::TestCase TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib') require File.join(TOP_SRC_DIR, 'columnize.rb') def test_parse_columnize_options assert Columnize.parse_columnize_options([{}]).kind_of?(Hash) assert_equal 90, Columnize.parse_columnize_options([90])[:displaywidth] opts = Columnize.parse_columnize_options([70, '|']) assert_equal 70, opts[:displaywidth] assert_equal '|', opts[:colsep] end def test_new_hash hash = {:displaywidth => 40, :colsep => ', ', :term_adjust => true,} assert_equal(hash, Columnize.parse_columnize_options([hash]), "parse_columnize_options returns same hash it was passed") end def test_array data = (0..54).to_a expected = "[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,\n" + " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,\n" + " 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,\n" + " 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,\n" + " 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,\n" + " 50, 51, 52, 53, 54]" assert_equal(expected, Columnize.columnize(data, :arrange_array => true, :ljust => false, :displaywidth => 39)) end def test_justify data = (0..54).to_a expected = "[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,\n" + " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,\n" + " 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,\n" + " 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,\n" + " 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,\n" + " 50, 51, 52, 53, 54]" assert_equal(expected, Columnize.columnize(data, :arrange_array => true, :displaywidth => 39)) end end columnize-0.9.0/test/test-columnizer.rb0000755000004100000410000001070512443740135020236 0ustar www-datawww-data#!/usr/bin/env ruby require 'test/unit' # Test of Columnizer class class TestColumnizer < Test::Unit::TestCase TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib') require File.join(TOP_SRC_DIR, 'columnize.rb') Columnize::Columnizer.class_eval 'attr_reader :stringify, :short_circuit, :term_adjuster' Columnize::Columnizer.class_eval 'attr_reader *ATTRS' # SETTING OPTS IN INITIALIZE def test_passed_in_opts # passed in opts should be merged with DEFAULT_OPTS c = Columnize::Columnizer.new([], :displaywidth => 15) assert_equal false, c.opts[:term_adjust], 'term_adjust comes from DEFAULT_OPTS' assert_equal 15, c.opts[:displaywidth], 'displaywidth should override DEFAULT_OPTS' end def test_ljust_attr c = Columnize::Columnizer.new([1,2,3], {:ljust => :auto}) assert_equal false, c.ljust, 'ljust: :auto should transform to false when all values are numeric' c = Columnize::Columnizer.new(['1', 2, 3], {:ljust => :auto}) assert_equal true, c.ljust, 'ljust: :auto should transform to true when not all values are numeric' c = Columnize::Columnizer.new([], {:ljust => false}) assert_equal false, c.ljust, 'ljust: false should stay false' c = Columnize::Columnizer.new([], {:ljust => true}) assert_equal true, c.ljust, 'ljust: true should stay true' end def test_stringify_attr c = Columnize::Columnizer.new assert_equal '1.0', c.stringify[1.0], 'without colfmt, should be to_s' c.update_opts :colfmt => '%02d' assert_equal '01', c.stringify[1.0], 'without colfmt, should be to_s' end def test_short_circuit_attr c = Columnize::Columnizer.new assert_equal "\n", c.short_circuit, 'should explicitly state when empty' c.list = 1 assert_equal '', c.short_circuit, 'should be an empty string when not an array' c.list = [1] assert_equal nil, c.short_circuit, 'should be nil when list is good' end def test_term_adjuster_attr c = Columnize::Columnizer.new assert_equal 'abc', c.term_adjuster['abc'] assert_equal "\e[0;31mObject\e[0;4m", c.term_adjuster["\e[0;31mObject\e[0;4m"] c.update_opts :term_adjust => true assert_equal 'abc', c.term_adjuster['abc'] assert_equal 'Object', c.term_adjuster["\e[0;31mObject\e[0;4m"] end def test_displaywidth_attr c = Columnize::Columnizer.new [], :displaywidth => 10, :line_prefix => ' ' assert_equal 12, c.displaywidth, 'displaywidth within 4 of line_prefix.length' c.update_opts :line_prefix => ' ' assert_equal 8, c.displaywidth, 'displaywidth not within 4 of line_prefix.length' end # COLUMNIZE def test_columnize_with_short_circuit msg = 'Johnny 5 is alive!' c = Columnize::Columnizer.new c.instance_variable_set(:@short_circuit, msg) assert_equal msg, c.columnize, 'columnize should return short_circuit message if set' end def test_columnize_applies_ljust c = Columnize::Columnizer.new [1,2,3,10,20,30], :displaywidth => 10, :ljust => false, :arrange_vertical => false assert_equal " 1 2 3\n10 20 30", c.columnize, "ljust: #{c.ljust}" c.update_opts :ljust => true assert_equal "1 2 3 \n10 20 30", c.columnize, "ljust: #{c.ljust}" end def no_test_columnize_applies_colsep_and_prefix_and_suffix c = Columnize::Columnizer.new [1,2,3] assert_equal "1 2 3", c.columnize c.update_opts :line_prefix => '>', :colsep => '-', :line_suffix => '<' assert_equal ">1-2-3<", c.columnize end def test_columnize_applies_array_prefix_and_suffix c = Columnize::Columnizer.new [1,2,3] assert_equal "1 2 3", c.columnize c.update_opts :array_prefix => '>', :array_suffix => '<' assert_equal ">1 2 3<", c.columnize end # NOTE: min_rows_and_colwidths tested in test-min_rows_and_colwidths.rb # arrange_rows_and_cols def test_arrange_rows_and_cols rows = Columnize::Columnizer.new.arrange_by_row((1..9).to_a, 3, 3) assert_equal [[1,2,3],[4,5,6],[7,8,9]], rows, 'rows for (1..9), 3, 3' cols = Columnize::Columnizer.new.arrange_by_column((1..9).to_a, 3, 3) assert_equal [[1,4,7],[2,5,8],[3,6,9]], cols, 'cols for (1..9), 3, 3' rows = Columnize::Columnizer.new.arrange_by_row((1..5).to_a, 3, 2) assert_equal [[1,2],[3,4],[5]], rows, 'rows for (1..5, 2, 3)' cols = Columnize::Columnizer.new.arrange_by_column((1..5).to_a, 3, 2) assert_equal [[1,3,5],[2,4]], cols, 'cols for (1..5, 2, 3)' end def test_set_attrs_from_opts assert(true, 'test set_attrs_from_opts') end end columnize-0.9.0/.gitignore0000644000004100000410000000001512443740135015544 0ustar www-datawww-data*~ /doc /pkg columnize-0.9.0/AUTHORS0000644000004100000410000000010212443740135014621 0ustar www-datawww-dataR. Bernstein (rockyb@rubyforge.net) M. Davis (waslogic@gmail.com) columnize-0.9.0/Makefile0000644000004100000410000000035712443740135015225 0ustar www-datawww-data# I'll admit it -- I'm an absent-minded old-timer who has trouble # learning new tricks. RUBY ?= ruby RAKE ?= rake test: check #: Default target; same as "make check" all: check true #: Same as corresponding rake task %: $(RAKE) $@ columnize-0.9.0/columnize.gemspec0000644000004100000410000000256612443740135017143 0ustar www-datawww-data# -*- Ruby -*- # -*- encoding: utf-8 -*- require File.dirname(__FILE__) + "/lib/columnize/version" unless Object.const_defined?(:'Columnize') Gem::Specification.new do |spec| spec.authors = ['Rocky Bernstein'] spec.date = Time.now spec.description = ' In showing a long lists, sometimes one would prefer to see the value arranged aligned in columns. Some examples include listing methods of an object or debugger commands. See Examples in the rdoc documentation for examples. ' spec.email = 'rockyb@rubyforge.net' spec.files = `git ls-files`.split("\n") spec.homepage = 'https://github.com/rocky/columnize' spec.name = 'columnize' spec.licenses = ['Ruby', 'GPL2'] spec.platform = Gem::Platform::RUBY spec.require_path = 'lib' spec.required_ruby_version = '>= 1.8.2' spec.rubyforge_project = 'columnize' spec.summary = 'Module to format an Array as an Array of String aligned in columns' spec.version = Columnize::VERSION spec.has_rdoc = true spec.extra_rdoc_files = %w(README.md lib/columnize.rb COPYING THANKS) # Make the readme file the start page for the generated html spec.rdoc_options += %w(--main README) spec.rdoc_options += ['--title', "Columnize #{Columnize::VERSION} Documentation"] spec.add_development_dependency 'rdoc' spec.add_development_dependency 'rake', '~> 10.1.0' end columnize-0.9.0/ChangeLog0000644000004100000410000002104712443740135015336 0ustar www-datawww-data2011-06-09 rocky * ChangeLog, NEWS, Rakefile: Get ready for new release. 2011-04-27 r * README.md: Fix code example. 2011-04-27 r * .gemspec, README, README.md, Rakefile: README->README.md 2011-04-27 r * .gemspec, AUTHORS, COPYING, ChangeLog, Makefile, NEWS, README, Rakefile, lib/Makefile, lib/columnize.rb, lib/version.rb, tags/release-0.2.1/AUTHORS, tags/release-0.2.1/COPYING, tags/release-0.2.1/ChangeLog, tags/release-0.2.1/NEWS, tags/release-0.2.1/README, tags/release-0.2.1/Rakefile, tags/release-0.2.1/VERSION, tags/release-0.2.1/lib/columnize.rb, tags/release-0.2.1/test/test-columnize.rb, tags/release-0.3.0/AUTHORS, tags/release-0.3.0/COPYING, tags/release-0.3.0/ChangeLog, tags/release-0.3.0/NEWS, tags/release-0.3.0/README, tags/release-0.3.0/Rakefile, tags/release-0.3.0/VERSION, tags/release-0.3.0/lib/columnize.rb, tags/release-0.3.0/test/test-columnize.rb, tags/release-0.3.1/AUTHORS, tags/release-0.3.1/COPYING, tags/release-0.3.1/ChangeLog, tags/release-0.3.1/NEWS, tags/release-0.3.1/README, tags/release-0.3.1/Rakefile, tags/release-0.3.1/VERSION, tags/release-0.3.1/lib/columnize.rb, tags/release-0.3.1/test/test-columnize.rb, test/test-columnize.rb, test/test-hashparm.rb, trunk/.gemspec, trunk/AUTHORS, trunk/COPYING, trunk/ChangeLog, trunk/Makefile, trunk/NEWS, trunk/README, trunk/Rakefile, trunk/lib/Makefile, trunk/lib/columnize.rb, trunk/lib/version.rb, trunk/test/test-columnize.rb, trunk/test/test-hashparm.rb: Remove trunk and tags. 2011-04-27 rockyb * trunk/ChangeLog, trunk/lib/columnize.rb, trunk/lib/version.rb, trunk/test/test-columnize.rb, trunk/test/test-hashparm.rb: Redo columnize options processing to allow for a single hash of options instead of the numerous optional arguments. This make future expansion easier. 2010-09-22 rockyb * trunk/Makefile, trunk/Rakefile: Rakefile: Remove bad test task Makefile: simplify. 2010-09-21 rockyb * trunk/Makefile, trunk/Rakefile: Makefile was a little off 2010-09-21 rockyb * trunk/.gemspec, trunk/Rakefile, trunk/lib/columnize.rb: Small changes to Rakefile and rdoc and so on. 2010-09-20 rockyb * trunk/.gemspec, trunk/Rakefile: Forgot to add .gemspec 2010-09-20 rockyb * trunk/ChangeLog, trunk/Makefile, trunk/NEWS, trunk/README, trunk/Rakefile, trunk/VERSION, trunk/lib/Makefile, trunk/lib/columnize.rb, trunk/lib/version.rb: Add .gemspec, correct description field and add a summary. Add Columnize::VERSION Simplify Rakefile Add stub Makefiles 2010-03-01 rockyb * trunk/README: Better README description 2010-03-01 rockyb * trunk/README: Update README 2010-02-22 rockyb * trunk/ChangeLog, trunk/VERSION, trunk/lib/columnize.rb: Remove shadow variable warnings. Bump version number 2009-07-26 rockyb * tags/release-0.3.1/AUTHORS, tags/release-0.3.1/COPYING, tags/release-0.3.1/ChangeLog, tags/release-0.3.1/NEWS, tags/release-0.3.1/README, tags/release-0.3.1/Rakefile, tags/release-0.3.1/VERSION, tags/release-0.3.1/lib/columnize.rb, tags/release-0.3.1/test/test-columnize.rb: Release 0.3.1 2009-07-26 rockyb * trunk/lib/columnize.rb: Small comment spelling typo. 2009-07-26 rockyb * trunk/ChangeLog: Get ready for 0.3.1 release 2009-07-26 rockyb * trunk/NEWS, trunk/lib/columnize.rb, trunk/test/test-columnize.rb: Add lineprefix. Get ready for release. 2009-07-26 mark-moseley * trunk/ChangeLog, trunk/lib/columnize.rb: Ruby 1.9 updates 2009-03-30 rockyb * trunk/Rakefile: Revise for 1.9 version of rake 2009-01-16 rockyb * trunk/ChangeLog, trunk/Rakefile, trunk/VERSION: package readme was wonky. Looks like no one reads this stuff. 2009-01-10 rockyb * tags/release-0.3.0/AUTHORS, tags/release-0.3.0/COPYING, tags/release-0.3.0/ChangeLog, tags/release-0.3.0/NEWS, tags/release-0.3.0/README, tags/release-0.3.0/Rakefile, tags/release-0.3.0/VERSION, tags/release-0.3.0/lib/columnize.rb, tags/release-0.3.0/test/test-columnize.rb: Release 0.3.0 2009-01-10 rockyb * trunk/ChangeLog, trunk/NEWS: Get ready for release 2009-01-08 rockyb * trunk/ChangeLog, trunk/NEWS, trunk/VERSION, trunk/lib/columnize.rb, trunk/test/test-columnize.rb: Fix bad bug in arranging horizontally 2009-01-01 rockyb * columnize/trunk/AUTHORS, columnize/trunk/COPYING, columnize/trunk/ChangeLog, columnize/trunk/NEWS, columnize/trunk/README, columnize/trunk/Rakefile, columnize/trunk/VERSION, columnize/trunk/lib/columnize.rb, columnize/trunk/test/test-columnize.rb: Remove hacky columnize/columnize 2009-01-01 rockyb * tags/columnize-0.2/AUTHORS, tags/columnize-0.2/COPYING, tags/columnize-0.2/ChangeLog, tags/columnize-0.2/NEWS, tags/columnize-0.2/README, tags/columnize-0.2/Rakefile, tags/columnize-0.2/VERSION, tags/columnize-0.2/lib/columnize.rb, tags/columnize-0.2/test/test-columnize.rb: Regularize tags names better 2009-01-01 rockyb * tags/release-0.2.1/AUTHORS, tags/release-0.2.1/COPYING, tags/release-0.2.1/ChangeLog, tags/release-0.2.1/NEWS, tags/release-0.2.1/README, tags/release-0.2.1/Rakefile, tags/release-0.2.1/VERSION, tags/release-0.2.1/lib/columnize.rb, tags/release-0.2.1/test/test-columnize.rb: Release 0.2.1 2009-01-01 rockyb * trunk/NEWS: Merge NEWS 2009-01-01 rockyb * columnize/tags/columnize-0.2/AUTHORS, columnize/tags/columnize-0.2/COPYING, columnize/tags/columnize-0.2/ChangeLog, columnize/tags/columnize-0.2/NEWS, columnize/tags/columnize-0.2/README, columnize/tags/columnize-0.2/Rakefile, columnize/tags/columnize-0.2/VERSION, columnize/tags/columnize-0.2/lib/columnize.rb, columnize/tags/columnize-0.2/test/test-columnize.rb, tags/columnize-0.2/AUTHORS, tags/columnize-0.2/COPYING, tags/columnize-0.2/ChangeLog, tags/columnize-0.2/NEWS, tags/columnize-0.2/README, tags/columnize-0.2/Rakefile, tags/columnize-0.2/VERSION, tags/columnize-0.2/lib/columnize.rb, tags/columnize-0.2/test/test-columnize.rb: Cleanup of columnize/columnize crap 2009-01-01 rockyb * : Add directory for releases 2009-01-01 rockyb * trunk/NEWS, trunk/VERSION: Ooops 0.2 release done. Go for 0.2.1 2009-01-01 rockyb * trunk/ChangeLog: Get ready for release 0.2 2009-01-01 rockyb * trunk/ChangeLog, trunk/NEWS, trunk/VERSION, trunk/lib/columnize.rb, trunk/test/test-columnize.rb: Get ready for release 0.2 2008-09-22 rockyb * columnize/tags/columnize-0.2/AUTHORS, columnize/tags/columnize-0.2/COPYING, columnize/tags/columnize-0.2/ChangeLog, columnize/tags/columnize-0.2/NEWS, columnize/tags/columnize-0.2/README, columnize/tags/columnize-0.2/Rakefile, columnize/tags/columnize-0.2/VERSION, columnize/tags/columnize-0.2/lib/columnize.rb, columnize/tags/columnize-0.2/test/test-columnize.rb: Tag 0.2 release. 2008-09-22 rockyb * : Add tags directory for release 2008-09-22 rockyb * columnize/trunk/ChangeLog, columnize/trunk/NEWS: Add directory for tagging releases. Other Administrivia. 2008-09-22 rockyb * columnize/trunk/VERSION, columnize/trunk/lib/columnize.rb: Get rid of hacky $0 test. 2008-03-16 rockyb * trunk/lib/columnize.rb: [no log message] 2008-03-16 rockyb * trunk/lib/columnize.rb: Simplify __FILE__ == $0. (rdebug now changes $0 and rcov has an option) 2008-02-11 rockyb * trunk/lib/columnize.rb: Remove 1.9's shadow warning 2007-12-10 rockyb * columnize/trunk/AUTHORS, columnize/trunk/COPYING, columnize/trunk/ChangeLog, columnize/trunk/NEWS, columnize/trunk/README, columnize/trunk/Rakefile, columnize/trunk/VERSION, columnize/trunk/lib/columnize.rb, columnize/trunk/test/test-columnize.rb: release 0.1 2007-12-09 rockyb * trunk/README, trunk/Rakefile: Fix up doc a little. Make the default rake task "test". 2007-12-09 rockyb * trunk/lib/columnize.rb: Doc fix. 2007-12-09 rockyb * trunk/ChangeLog, trunk/lib/columnize.rb, trunk/test/test-columnize.rb: columnize.rb: Allow one to specify a separator string. Remove restriction that all entries in the array have to be a string. test-columnize.rb: more tests - invalid list, empty list, with separator string parameter. 2007-12-09 rockyb * trunk/test/test-columnize.rb: Typo. 2007-12-09 rockyb * : Property changes for Id lines and to make test-columnize.rb executable. 2007-12-09 rockyb * Initial release of Columnize, a module to print an Array in column-sorted order. columnize-0.9.0/README.md0000644000004100000410000000515412443740135015044 0ustar www-datawww-data[![Build Status](https://travis-ci.org/rocky/columnize.png)](https://travis-ci.org/rocky/columnize) [![Gem Version](https://badge.fury.io/rb/columnize.svg)](http://badge.fury.io/rb/columnize) Columnize - Format an Array as a Column-aligned String ============================================================================ In showing a long lists, sometimes one would prefer to see the value arranged aligned in columns. Some examples include listing methods of an object, listing debugger commands, or showing a numeric array with data aligned. Setup ----- $ irb >> require 'columnize' => true With numeric data ----------------- >> a = (1..10).to_a => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >> a.columnize => "1 2 3 4 5 6 7 8 9 10" >> puts a.columnize :arrange_array => true, :displaywidth => 10 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] => nil >> puts a.columnize :arrange_array => true, :displaywidth => 20 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] => nil With String data ---------------- >> g = %w(bibrons golden madascar leopard mourning suras tokay) => ["bibrons", "golden", "madascar", "leopard", "mourning", "suras", "tokay"] >> puts g.columnize :displaywidth => 15 bibrons suras golden tokay madascar leopard mourning => nil >> puts g.columnize :displaywidth => 19, :colsep => ' | ' bibrons | suras golden | tokay madascar leopard mourning => nil >> puts g.columnize :displaywidth => 18, :colsep => ' | ', :ljust => false bibrons | mourning golden | suras madascar | tokay leopard => nil Using Columnize.columnize ------------------------- >> Columnize.columnize(a) => "1 2 3 4 5 6 7 8 9 10" >> puts Columnize.columnize(a, :displaywidth => 10) 1 5 9 2 6 10 3 7 4 8 => nil >> Columnize.columnize(g) => "bibrons golden madascar leopard mourning suras tokay" >> puts Columnize.columnize(g, :displaywidth => 19, :colsep => ' | ') bibrons | mourning golden | suras madascar | tokay leopard => nil Credits ------- This is adapted from a method of the same name from Python's cmd module. Other stuff ----------- Authors: Rocky Bernstein [![endorse](https://api.coderwall.com/rocky/endorsecount.png)](https://coderwall.com/rocky) and [Martin Davis](https://github.com/waslogic) License: Copyright (c) 2011,2013 Rocky Bernstein Warranty -------- You can redistribute it and/or modify it under either the terms of the GPL version 2 or the conditions listed in COPYING columnize-0.9.0/COPYING0000644000004100000410000000467212443740135014624 0ustar www-datawww-dataColumnize is copyrighted free software by Rocky Bernstein . You can redistribute it and/or modify it under either the terms of the GPL version 2, or the conditions below: 1. You may make and give away verbatim copies of the source form of the software without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may modify your copy of the software in any way, provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or by allowing the author to include your modifications in the software. b) use the modified software only within your corporation or organization. c) give non-standard binaries non-standard names, with instructions on where to get the original software distribution. d) make other distribution arrangements with the author. 3. You may distribute the software in object code or binary form, provided that you do at least ONE of the following: a) distribute the binaries and library files of the software, together with instructions (in the manual page or equivalent) on where to get the original distribution. b) accompany the distribution with the machine-readable source of the software. c) give non-standard binaries non-standard names, with instructions on where to get the original software distribution. d) make other distribution arrangements with the author. 4. You may modify and include the part of the software into any other software (possibly commercial). But some files in the distribution are not written by the author, so that they are not under these terms. For the list of those files and their copying conditions, see the file LEGAL. 5. The scripts and library files supplied as input to or produced as output from the software do not automatically fall under the copyright of the software, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this software. 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.