Sha256: ca07280e0000163006cc4e0f96e2a3c82c2a0018ff5043288e2a929ed6204e2c

Contents?: true

Size: 862 Bytes

Versions: 1

Compression:

Stored size: 862 Bytes

Contents

class Datagrid::Columns::Column

  attr_accessor :grid, :options, :block, :name

  def initialize(grid, name, options = {}, &block)
    self.grid = grid
    self.name = name
    self.options = options
    self.block = block
  end

  def value(object)
    value_for(object)
  end

  def value_for(object)
    object.instance_eval(&self.block)
  end

  def format
    self.options[:format]
  end

  def label
    self.options[:label]
  end

  def header
    self.options[:header] || 
      I18n.translate(self.name, :scope => "reports.#{self.grid}.columns", :default => self.name.to_s.humanize )
  end

  def order
    if options.has_key?(:order)
      self.options[:order]
    else
      grid.scope.column_names.include?(name.to_s) ? [grid.scope.table_name, name].join(".") : nil
    end
  end

  def desc_order
    order ? order.to_s + " DESC" : nil
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datagrid-0.0.3 lib/datagrid/columns/column.rb