class TablePrint::Column
Attributes
data[RW]
default_width[RW]
fixed_width[RW]
formatters[R]
min_width[RW]
name[RW]
time_format[RW]
Public Class Methods
new(attr_hash={})
click to toggle source
# File lib/table_print/column.rb, line 6 def initialize(attr_hash={}) @formatters = [] attr_hash.each do |k, v| self.send("#{k}=", v) end end
Public Instance Methods
add_formatter(formatter)
click to toggle source
# File lib/table_print/column.rb, line 32 def add_formatter(formatter) @formatters << formatter end
data_width()
click to toggle source
# File lib/table_print/column.rb, line 36 def data_width if multibyte_count [ name.each_char.collect{|c| c.bytesize == 1 ? 1 : 2}.inject(0, &:+), Array(data).compact.collect(&:to_s).collect{|m| m.each_char.collect{|n| n.bytesize == 1 ? 1 : 2}.inject(0, &:+)}.max ].compact.max || 0 else [ name.length, Array(data).compact.collect(&:to_s).collect(&:length).max ].compact.max || 0 end end
display_method()
click to toggle source
# File lib/table_print/column.rb, line 28 def display_method @display_method ||= name end
display_method=(method)
click to toggle source
# File lib/table_print/column.rb, line 23 def display_method=(method) method = method.to_s unless method.is_a? Proc @display_method = method end
formatters=(formatter_list)
click to toggle source
# File lib/table_print/column.rb, line 17 def formatters=(formatter_list) formatter_list.each do |f| add_formatter(f) end end
name=(n)
click to toggle source
# File lib/table_print/column.rb, line 13 def name=(n) @name = n.to_s end
width()
click to toggle source
# File lib/table_print/column.rb, line 50 def width return fixed_width if fixed_width width = [(default_width || max_width), data_width].min [(min_width || 0), width].max end
Private Instance Methods
max_width()
click to toggle source
# File lib/table_print/column.rb, line 58 def max_width TablePrint::Config.max_width end
multibyte_count()
click to toggle source
# File lib/table_print/column.rb, line 62 def multibyte_count TablePrint::Config.multibyte end