Sha256: 0cf4735cf353477f687a4796f8a53fb157abcc3bcb39aa493bfd727b29773cb6

Contents?: true

Size: 545 Bytes

Versions: 5

Compression:

Stored size: 545 Bytes

Contents

module TableCloth
  class Column
    attr_reader :options, :name

    def initialize(name, options={})
      @name = name
      @options = options
    end

    def value(object, view, table=nil)
      if options[:proc].respond_to?(:call)
        view.instance_exec(object, view, &options[:proc])
      else
        object.send(name)
      end
    end

    def human_name(view)
      if options[:label].kind_of? Proc
        view.instance_exec(&options[:label])
      else
        options[:label] || name.to_s.humanize
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
table_cloth-0.4.3 lib/table_cloth/column.rb
table_cloth-0.4.2 lib/table_cloth/column.rb
table_cloth-0.4.1 lib/table_cloth/column.rb
table_cloth-0.4.0 lib/table_cloth/column.rb
table_cloth-0.3.2 lib/table_cloth/column.rb