Class: TableCloth::Presenter
- Inherits:
-
Object
- Object
- TableCloth::Presenter
show all
- Defined in:
- lib/table_cloth/presenter.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(objects, table, view) ⇒ Presenter
Returns a new instance of Presenter.
5
6
7
8
9
|
# File 'lib/table_cloth/presenter.rb', line 5
def initialize(objects, table, view)
@objects = objects
@view_context = view
@table = table.new(objects, view)
end
|
Instance Attribute Details
#objects ⇒ Object
Returns the value of attribute objects.
3
4
5
|
# File 'lib/table_cloth/presenter.rb', line 3
def objects
@objects
end
|
#table ⇒ Object
Returns the value of attribute table.
3
4
5
|
# File 'lib/table_cloth/presenter.rb', line 3
def table
@table
end
|
#view_context ⇒ Object
Returns the value of attribute view_context.
3
4
5
|
# File 'lib/table_cloth/presenter.rb', line 3
def view_context
@view_context
end
|
Instance Method Details
#columns ⇒ Object
23
24
25
26
27
28
|
# File 'lib/table_cloth/presenter.rb', line 23
def columns
@columns ||= table.class.columns.map do |name, column_hash|
column = column_hash[:class].new(name, column_hash[:options])
ColumnJury.new(column, table).available? ? column : nil
end.compact
end
|
#render_table ⇒ Object
11
12
13
|
# File 'lib/table_cloth/presenter.rb', line 11
def render_table
raise NoMethodError, "You must override the .render method"
end
|
#row_values(object) ⇒ Object
30
31
32
33
34
|
# File 'lib/table_cloth/presenter.rb', line 30
def row_values(object)
columns.each_with_object([]) do |column, values|
values << column.value(object, view_context, table)
end
end
|
#rows ⇒ Object
36
37
38
39
40
|
# File 'lib/table_cloth/presenter.rb', line 36
def rows
objects.each_with_object([]) do |object, row|
row << row_values(object)
end
end
|
#tbody ⇒ Object
19
20
21
|
# File 'lib/table_cloth/presenter.rb', line 19
def tbody
raise NoMethodError, "You must override the .rows method"
end
|
#thead ⇒ Object
15
16
17
|
# File 'lib/table_cloth/presenter.rb', line 15
def thead
raise NoMethodError, "You must override the .header method"
end
|