Sha256: ae8a8531a8e570213df75cd0a8ab2c45fae22c4e55ac96ef3df511c164e2e4d7

Contents?: true

Size: 562 Bytes

Versions: 5

Compression:

Stored size: 562 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
    ret = reduce([]) do |rets, lines|
      ret = lines.reduce([]) { |ret, column|ret << column; ret }
      rets << "|#{ret.join("|")}|"
    end.join("\n") + "\n"
    ret.justify_table(:center)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.83 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.82 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.81 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.80 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.79 lib/open_classes/array/to_table.rb