Sha256: 248d0d5952a5593b7db406045b2bae1eb781e56254e185f23235473f16996c62

Contents?: true

Size: 582 Bytes

Versions: 33

Compression:

Stored size: 582 Bytes

Contents

# encoding: utf-8
require 'open_classes/string/justify_table'

# Array
class Array
  # Array(Array, Array...) to table format.
  #
  # === Example
  #
  #   [['header1', 'header2', 'header3'],['line1_1', 'line1_2', 'line1_3']].to_table
  #
  # result
  #   |header1|header2|header3|
  #   |line1_1|line1_2|line1_3|
  #
  def to_table(position = :right)
    ret = reduce([]) do |rets, lines|
      ret = lines.reduce([]) { |ret, column|ret << column; ret }
      rets << "|#{ret.join("|")}|"
    end.join("\n") + "\n"
    ret.justify_table(position)
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.116 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.115 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.114 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.113 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.112 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.111 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.110 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.109 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.108 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.107 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.106 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.105 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.104 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.103 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.102 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.101 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.100 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.99 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.98 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.97 lib/open_classes/array/to_table.rb