Sha256: 589632e43c05bd8aacf1b0c79f7bfe60f55f1511dd6803ac23fa2d697df071e3

Contents?: true

Size: 853 Bytes

Versions: 7

Compression:

Stored size: 853 Bytes

Contents

module TablePrint
  class Column
    attr_reader :formatters
    attr_writer :width
    attr_accessor :name, :data, :time_format

    def initialize(attr_hash={})
      @formatters = []
      attr_hash.each do |k, v|
        self.send("#{k}=", v)
      end
    end

    def name=(n)
      @name = n.to_s
    end

    def formatters=(formatter_list)
      formatter_list.each do |f|
        add_formatter(f)
      end
    end

    def display_method=(method)
      method = method.to_s unless method.is_a? Proc
      @display_method = method
    end

    def display_method
      @display_method ||= name
    end

    def add_formatter(formatter)
      @formatters << formatter
    end

    def data_width
      [name.length].concat(data.compact.collect(&:to_s).collect(&:length)).max
    end

    def width
      @width ||= data_width
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
table_print-1.1.3 lib/table_print/column.rb
table_print-1.1.2 lib/table_print/column.rb
table_print-1.1.1 lib/table_print/column.rb
table_print-1.1.0 lib/table_print/column.rb
table_print-1.0.1 lib/table_print/column.rb
table_print-1.0.0 lib/table_print/column.rb
table_print-1.0.0.rc3 lib/column.rb