Class: EasyTable::Column

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

Direct Known Subclasses

ActionColumn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Column.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#value_blockObject (readonly)

Returns the value of attribute value_block.



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

def value_block
  @value_block
end

Instance Method Details

#header(table, view) ⇒ Object



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

def header(table, view)
  if options[:header].present?
    options[:header]
  elsif table.model_class
    table.model_class.human_attribute_name(name)
  end
end

#td_htmlObject



21
22
23
# File 'lib/easy_table/column.rb', line 21

def td_html
  Config.td_html
end

#th_htmlObject



17
18
19
# File 'lib/easy_table/column.rb', line 17

def th_html
  Config.th_html
end

#value(item, view) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/easy_table/column.rb', line 25

def value(item, view)
  if value_block
    view.capture(item, &value_block)
  else
    item.send(name)
  end
end