Class: RenderTable::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/render_table/cell.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header, row, cell_index, table) ⇒ Cell

Returns a new instance of Cell.



10
11
12
13
14
15
16
# File 'lib/render_table/cell.rb', line 10

def initialize(header, row, cell_index, table)
  @header = header
  @row = row
  @cell_index = cell_index
  @table = table
  @html = @table.html[:cells]
end

Instance Attribute Details

#cell_indexObject

Returns the value of attribute cell_index.



2
3
4
# File 'lib/render_table/cell.rb', line 2

def cell_index
  @cell_index
end

#headerObject

Returns the value of attribute header.



2
3
4
# File 'lib/render_table/cell.rb', line 2

def header
  @header
end

#htmlObject

Returns the value of attribute html.



2
3
4
# File 'lib/render_table/cell.rb', line 2

def html
  @html
end

Class Method Details

.cells_for_row(row, table) ⇒ Object



4
5
6
7
8
# File 'lib/render_table/cell.rb', line 4

def self.cells_for_row(row, table)
  table.header.collect.with_index do |header_cell, cell_index|
    RenderTable::Cell.new(header_cell, row, cell_index, table)
  end
end

Instance Method Details

#classObject



26
27
28
# File 'lib/render_table/cell.rb', line 26

def class
  RenderTable::Html.html_string(@html[:classes], value, @cell_index)
end

#idObject



30
31
32
# File 'lib/render_table/cell.rb', line 30

def id
  RenderTable::Html.html_string(@html[:ids], value, @cell_index)
end

#valueObject



18
19
20
21
22
23
24
# File 'lib/render_table/cell.rb', line 18

def value
  record = @row.record
  overriden_header = @table.override[header]
  return overriden_header.call(record, @cell_index) if overriden_header
  return record.send(header) if @row.record.respond_to? header
  RenderTable.config.cell_value
end