Class: Tableficate::Column

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

Direct Known Subclasses

ActionColumn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Column.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tableficate/column.rb', line 5

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

  @header       = options.delete(:header) || name.to_s.titleize
  @header_attrs = options.delete(:header_attrs) || {}

  @cell_attrs = options.delete(:cell_attrs) || {}

  @show_sort = options.delete(:show_sort) || false

  @attrs = options
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



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

def attrs
  @attrs
end

#cell_attrsObject (readonly)

Returns the value of attribute cell_attrs.



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

def cell_attrs
  @cell_attrs
end

#headerObject (readonly)

Returns the value of attribute header.



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

def header
  @header
end

#header_attrsObject (readonly)

Returns the value of attribute header_attrs.



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

def header_attrs
  @header_attrs
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#tableObject (readonly)

Returns the value of attribute table.



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

def table
  @table
end

Instance Method Details

#is_sorted?(dir = nil) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/tableficate/column.rb', line 38

def is_sorted?(dir = nil)
  is_sorted = @table.current_sort[:column] == self.name
  is_sorted = @table.current_sort[:dir] == dir if is_sorted and dir

  is_sorted
end

#show_sort?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/tableficate/column.rb', line 34

def show_sort?
  @show_sort
end

#value(row) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tableficate/column.rb', line 20

def value(row)
  if @block
    output = @block.call(row)
    if output.is_a?(ActionView::OutputBuffer)
      ''
    else
      output = output.html_safe if output.respond_to? :html_safe
      output
    end
  else
    row.send(@name)
  end
end