Class: PaginatedTable::ColumnDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/paginated_table/column_description.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ColumnDescription.



5
6
7
8
9
10
# File 'lib/paginated_table/column_description.rb', line 5

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/paginated_table/column_description.rb', line 3

def name
  @name
end

Instance Method Details

#html_attributesObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/paginated_table/column_description.rb', line 32

def html_attributes
  html_attributes = {}
  if @options[:class]
    html_attributes[:class] = Array(@options[:class]).join(' ')
  end
  if @options[:style]
    html_attributes[:style] = @options[:style]
  end
  if span
    html_attributes[:colspan] = @row.colspan(span)
  end
  html_attributes
end

#render_cell(datum) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/paginated_table/column_description.rb', line 16

def render_cell(datum)
  if @block
    @block.call(datum)
  else
    datum.send(@name)
  end
end

#render_headerObject



12
13
14
# File 'lib/paginated_table/column_description.rb', line 12

def render_header
  @options.fetch(:title, @name.to_s.titleize)
end

#sortable?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/paginated_table/column_description.rb', line 24

def sortable?
  @options.fetch(:sortable, true)
end

#spanObject



28
29
30
# File 'lib/paginated_table/column_description.rb', line 28

def span
  @options.fetch(:span, false)
end