class Term::Table
Attributes
TODO:
-
make Table's configuration eaiser to remember by putting the formatting parameters in initialize eg:
Table.new
(elements, :sort=>:vertical).to_s
TODO:
-
make Table's configuration eaiser to remember by putting the formatting parameters in initialize eg:
Table.new
(elements, :sort=>:vertical).to_s
TODO:
-
make Table's configuration eaiser to remember by putting the formatting parameters in initialize eg:
Table.new
(elements, :sort=>:vertical).to_s
TODO:
-
make Table's configuration eaiser to remember by putting the formatting parameters in initialize eg:
Table.new
(elements, :sort=>:vertical).to_s
TODO:
-
make Table's configuration eaiser to remember by putting the formatting parameters in initialize eg:
Table.new
(elements, :sort=>:vertical).to_s
TODO:
-
make Table's configuration eaiser to remember by putting the formatting parameters in initialize eg:
Table.new
(elements, :sort=>:vertical).to_s
TODO:
-
make Table's configuration eaiser to remember by putting the formatting parameters in initialize eg:
Table.new
(elements, :sort=>:vertical).to_s
Public Class Methods
# File lib/epitools/term.rb, line 107 def self.[](data) self.new(data) end
# File lib/epitools/term.rb, line 111 def initialize(data, options={}) @data = data.map(&:to_s) @strip_color = options[:ansi] || options[:colorized] || options[:colored] || options[:strip_color] || options[:strip_ansi] if strip_color @max_size = @data.map { |e| e.strip_color.size }.max else @max_size = @data.map(&:size).max end @indent = options[:indent] || 0 @border = options[:border] @columns = options[:columns] @padding = options[:padding] || 1 if (options.keys & [:horiz, :horizontal, :horizontally]).any? @direction = :horizontal else @direction = :vertical end # Update the terminal size @width, @height = Term.size end
Public Instance Methods
# File lib/epitools/term.rb, line 148 def column_order cols = [] @data.each_slice(num_rows) { |col| cols << col } if (diff = cols.first.size - cols.last.size) > 0 cols.last.concat [''] * diff end cols.transpose end
# File lib/epitools/term.rb, line 188 def display #(opts={}) case @direction when :horizontal puts in_rows when :vertical puts in_columns end end
# File lib/epitools/term.rb, line 175 def in_columns return '' if @data.empty? render sliced_into(num_rows).transpose end
# File lib/epitools/term.rb, line 182 def in_rows return '' if @data.empty? render sliced_into(num_columns) end
# File lib/epitools/term.rb, line 136 def num_columns return @columns if @columns w = @width w -= indent cols = (w-2) / (@max_size + @padding) cols > 0 ? cols : 1 end
# File lib/epitools/term.rb, line 144 def num_rows (@data.size / num_columns.to_f).ceil end
# File lib/epitools/term.rb, line 201 def render(rows, options={}) num_cols = rows.first.size result = [] if @border separator = "+#{(["-" * @max_size] * num_cols).join('+')}+" result << separator end for row in rows justified = row.map do |e| if (diff = @max_size - e.strip_color.size) > 0 e = e + (" " * diff) end e end if @border line = "|#{justified.join('|')}|" else line = justified.join(' '*@padding) end result << (" "*indent) + line end result << separator if @border result.join("\n") end
# File lib/epitools/term.rb, line 157 def row_order rows = [] @data.each_slice(num_columns) { |row| rows << row } if (diff = rows.first.size - rows.last.size) > 0 rows.last.concat [''] * diff end rows end
# File lib/epitools/term.rb, line 166 def sliced_into(n) elems = [] @data.each_slice(n) { |e| elems << e } if (diff = elems.first.size - elems.last.size) > 0 elems.last.concat [''] * diff end elems end
# File lib/epitools/term.rb, line 197 def to_s by_rows end