class DiningTable::Columns::Column

Attributes

block[RW]
name[RW]
options[RW]
table[RW]

Public Class Methods

new( table, name, options = {}, &block) click to toggle source
# File lib/dining-table/columns/column.rb, line 9
def initialize( table, name, options = {}, &block)
  self.table = table
  self.name = name
  self.options = options
  self.block = block
end

Public Instance Methods

header() click to toggle source
# File lib/dining-table/columns/column.rb, line 24
def header
  @header ||= begin
    label = determine_label(:header)
    return label if label
    object_class = table.collection.first.class if table.collection.first
    object_class ||= table.object_class if !object_class
    object_class.human_attribute_name( name ) if object_class && object_class.respond_to?( :human_attribute_name )
  end
end
options_for(identifier) click to toggle source
# File lib/dining-table/columns/column.rb, line 38
def options_for(identifier)
  options[ identifier ] || { }
end
value(object) click to toggle source
# File lib/dining-table/columns/column.rb, line 16
def value(object)
  if block
    block.call(object, self)
  else
    object.send(name) if object.respond_to?(name)
  end
end

Private Instance Methods

determine_label( name ) click to toggle source
# File lib/dining-table/columns/column.rb, line 44
def determine_label( name )
  if options[ name ]
    label_ = options[ name ]
    label_ = label_.call if label_.respond_to?(:call)
    label_ = label_.to_s if label_.respond_to?(:to_s)
    return label_
  end
end