Class: Compendium::Presenters::Table

Inherits:
Query
  • Object
show all
Defined in:
app/classes/compendium/presenters/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_s

Constructor Details

#initialize {|@settings| ... } ⇒ Table

Returns a new instance of Table.

Yields:

  • (@settings)


5
6
7
8
9
10
11
12
13
# File 'app/classes/compendium/presenters/table.rb', line 5

def initialize(*)
  super

  @records = results.records
  @totals = @records.pop if has_totals_row?

  @settings = settings_class.new(results.keys)
  yield @settings if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Compendium::Presenters::Base

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



3
4
5
# File 'app/classes/compendium/presenters/table.rb', line 3

def records
  @records
end

#totalsObject (readonly)

Returns the value of attribute totals.



3
4
5
# File 'app/classes/compendium/presenters/table.rb', line 3

def totals
  @totals
end

Instance Method Details

#renderObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/classes/compendium/presenters/table.rb', line 15

def render
  (:table, class: 'results') do
    table = ActiveSupport::SafeBuffer.new
    table << (:thead, build_heading_row)
    table << (:tbody) do
      tbody = ActiveSupport::SafeBuffer.new
      records.each { |row| tbody << build_data_row(row) }
      tbody
    end
    table << (:tfoot, build_totals_row) if has_totals_row?
    table
  end
end