Class: TableCloth::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/table_cloth/presenter.rb

Direct Known Subclasses

TableCloth::Presenters::Default

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

#objectsObject (readonly)

Returns the value of attribute objects.



3
4
5
# File 'lib/table_cloth/presenter.rb', line 3

def objects
  @objects
end

#tableObject (readonly)

Returns the value of attribute table.



3
4
5
# File 'lib/table_cloth/presenter.rb', line 3

def table
  @table
end

#view_contextObject (readonly)

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

#columnsObject



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_tableObject

Raises:

  • (NoMethodError)


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

#rowsObject



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

#tbodyObject

Raises:

  • (NoMethodError)


19
20
21
# File 'lib/table_cloth/presenter.rb', line 19

def tbody
  raise NoMethodError, "You must override the .rows method"
end

#theadObject

Raises:

  • (NoMethodError)


15
16
17
# File 'lib/table_cloth/presenter.rb', line 15

def thead
  raise NoMethodError, "You must override the .header method"
end