Class: DiningTable::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/dining-table/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, view_context, options = {}) ⇒ Table

Returns a new instance of Table.



10
11
12
13
14
15
16
17
18
# File 'lib/dining-table/table.rb', line 10

def initialize( collection, view_context, options = {} )
  self.collection = collection
  self.view_context = view_context
  self.index     = 0
  self.columns   = [ ]
  self.options   = options
  initialize_presenter( options )
  define
end

Instance Attribute Details

#action_columnsObject

Returns the value of attribute action_columns.



5
6
7
# File 'lib/dining-table/table.rb', line 5

def action_columns
  @action_columns
end

#collectionObject

Returns the value of attribute collection.



5
6
7
# File 'lib/dining-table/table.rb', line 5

def collection
  @collection
end

#columnsObject

Returns the value of attribute columns.



5
6
7
# File 'lib/dining-table/table.rb', line 5

def columns
  @columns
end

#indexObject

Returns the value of attribute index.



5
6
7
# File 'lib/dining-table/table.rb', line 5

def index
  @index
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/dining-table/table.rb', line 5

def options
  @options
end

#presenterObject

Returns the value of attribute presenter.



5
6
7
# File 'lib/dining-table/table.rb', line 5

def presenter
  @presenter
end

#view_contextObject

Returns the value of attribute view_context.



5
6
7
# File 'lib/dining-table/table.rb', line 5

def view_context
  @view_context
end

Instance Method Details

#defineObject

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/dining-table/table.rb', line 20

def define
  raise NotImplementedError
end

#helpersObject Also known as: h



38
39
40
# File 'lib/dining-table/table.rb', line 38

def helpers
  view_context
end

#object_classObject



51
52
53
# File 'lib/dining-table/table.rb', line 51

def object_class
  options[:class]
end

#renderObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dining-table/table.rb', line 24

def render
  presenter.start_table
  presenter.render_header unless no_header
  presenter.start_body
  collection.each_with_index do |object, index_|
    self.index = index_
    presenter.render_row( object )
  end
  presenter.end_body
  presenter.render_footer unless no_footer
  presenter.end_table
  presenter.output
end


47
48
49
# File 'lib/dining-table/table.rb', line 47

def skip_footer
  self.no_footer = true
end

#skip_headerObject



43
44
45
# File 'lib/dining-table/table.rb', line 43

def skip_header
  self.no_header = true
end