Class: TableHelper::Column

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

Overview

:nodoc:

Direct Known Subclasses

CallbackColumn, SimpleColumn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, records, obj, ops = {}) ⇒ Column

Returns a new instance of Column.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/table_for/column.rb', line 6

def initialize(template, records, obj, ops={})
  @template, @attr, @options = template, obj, ops

  @title = if @options[:title]
    @options.delete(:title)
  elsif @attr.nil?
    " "
  elsif records.class.respond_to?(:human_attribute_name)
    records.class.human_attribute_name(@attr.to_s)
  elsif @attr.to_s.respond_to?(:humanize)
    @attr.to_s.humanize
  else
    @attr.to_s.capitalize
  end
  
  @title_callback = @options.delete(:title_callback)

  @html  = @options.delete(:html)  || {}
  @html.merge!({:th => { :width => @options.delete(:width) }}) if @options.has_key?(:width)
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



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

def html
  @html
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

Instance Method Details

#content_forObject

Raises:

  • (NoMethodError)


27
28
29
# File 'lib/table_for/column.rb', line 27

def content_for
  raise NoMethodError, "Use SimpleColumn or CallbackColumn"
end

#draw_titleObject



31
32
33
34
35
# File 'lib/table_for/column.rb', line 31

def draw_title
   :th, @html[:th] do
    @title_callback.is_a?(Proc) ? @title_callback.call(@title) : @title
  end
end