Class: TableHelp::TableFor

Inherits:
Object
  • Object
show all
Defined in:
lib/table_help/table_for.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, context, options = {}) ⇒ TableFor

Returns a new instance of TableFor.



6
7
8
9
10
11
12
# File 'lib/table_help/table_for.rb', line 6

def initialize(collection, context, options = {})
  @collection   = collection
  @context      = context
  @options      = default_options.merge(options)
  @column_names = []
  @strategies   = []
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



3
4
5
# File 'lib/table_help/table_for.rb', line 3

def collection
  @collection
end

#column_namesObject (readonly)

Returns the value of attribute column_names.



3
4
5
# File 'lib/table_help/table_for.rb', line 3

def column_names
  @column_names
end

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/table_help/table_for.rb', line 3

def context
  @context
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/table_help/table_for.rb', line 3

def options
  @options
end

#strategiesObject (readonly)

Returns the value of attribute strategies.



3
4
5
# File 'lib/table_help/table_for.rb', line 3

def strategies
  @strategies
end

Instance Method Details

#column(name = nil, method_name = nil, &block) ⇒ Object



14
15
16
17
# File 'lib/table_help/table_for.rb', line 14

def column(name = nil, method_name = nil, &block)
  column_names << Formatter.format_attribute_name(name, collection)
  strategies << Strategy.new(name, block_given? ? block : method_name)
end

#to_htmlObject



19
20
21
22
23
24
25
26
# File 'lib/table_help/table_for.rb', line 19

def to_html
  return if collection.empty?

  tag.table(options) do
    concat thead
    concat tbody
  end
end