Sha256: 753328bd062428b02907eb69fd2c1b7637c4b2bfb23d032cb9984c9d08f2a84b

Contents?: true

Size: 582 Bytes

Versions: 34

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

34 entries across 34 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.150 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.149 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.148 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.147 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.146 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.145 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.144 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.143 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.142 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.141 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.140 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.139 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.138 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.137 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.136 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.135 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.134 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.133 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.132 lib/open_classes/array/to_table.rb
tbpgr_utils-0.0.131 lib/open_classes/array/to_table.rb