Class: DiningTable::Columns::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/dining-table/columns/column.rb

Direct Known Subclasses

ActionsColumn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, name, options = {}, &block) ⇒ Column

Returns a new instance of Column.



9
10
11
12
13
14
# 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

Instance Attribute Details

#blockObject

Returns the value of attribute block.



7
8
9
# File 'lib/dining-table/columns/column.rb', line 7

def block
  @block
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/dining-table/columns/column.rb', line 7

def name
  @name
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/dining-table/columns/column.rb', line 7

def options
  @options
end

#tableObject

Returns the value of attribute table.



7
8
9
# File 'lib/dining-table/columns/column.rb', line 7

def table
  @table
end

Instance Method Details



34
35
36
# File 'lib/dining-table/columns/column.rb', line 34

def footer
  @footer ||= determine_label(:footer)
end

#headerObject



24
25
26
27
28
29
30
31
32
# 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) ⇒ Object



38
39
40
# File 'lib/dining-table/columns/column.rb', line 38

def options_for(identifier)
  options[ identifier ] || { }
end

#value(object) ⇒ Object



16
17
18
19
20
21
22
# 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