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
# File 'lib/tableficate/column.rb', line 5

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

  @header = @options.delete(:header) || name.to_s.titleize
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



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

def header
  @header
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)


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

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)


28
29
30
# File 'lib/tableficate/column.rb', line 28

def show_sort?
  !!@options[:show_sort]
end

#value(row) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tableficate/column.rb', line 14

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