Sha256: 4dbd89405e4ece5eb6d5b5930bd0f907f0a74ee9f055ff74d55896a1bdc8032b

Contents?: true

Size: 720 Bytes

Versions: 4

Compression:

Stored size: 720 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] && options[:proc].respond_to?(:call)
        view.instance_exec(object, view, &options[:proc])
      else
        object.send(name)
      end
    end

    def human_name
      options[:label] || name.to_s.humanize
    end

    def available?(table)
      if options[:if] && options[:if].is_a?(Symbol)
        return !!table.send(options[:if])
      end

      if options[:unless] && options[:unless].is_a?(Symbol)
        return !table.send(options[:unless])
      end

      true
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
table_cloth-0.2.3 lib/table_cloth/column.rb
table_cloth-0.2.2 lib/table_cloth/column.rb
table_cloth-0.2.1 lib/table_cloth/column.rb
table_cloth-0.2.0 lib/table_cloth/column.rb