Class: TableCloth::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/table_cloth/column.rb

Direct Known Subclasses

Extensions::Actions::Column

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Column.


5
6
7
8
# File 'lib/table_cloth/column.rb', line 5

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


3
4
5
# File 'lib/table_cloth/column.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options


3
4
5
# File 'lib/table_cloth/column.rb', line 3

def options
  @options
end

Instance Method Details

#human_name(view) ⇒ Object


18
19
20
21
22
23
24
# File 'lib/table_cloth/column.rb', line 18

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

#value(object, view, table = nil) ⇒ Object


10
11
12
13
14
15
16
# File 'lib/table_cloth/column.rb', line 10

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