Class: TableHelp::TableFor

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

Defined Under Namespace

Classes: Column

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of TableFor.



8
9
10
11
12
13
14
15
# File 'lib/table_help/table_for.rb', line 8

def initialize(collection, context, options = {})
  @collection   = collection
  @context      = context
  @options      = default_options.merge(options)
  @columns      = []
  @strategies   = []
  @q            = @options.delete(:q)
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



5
6
7
# File 'lib/table_help/table_for.rb', line 5

def collection
  @collection
end

#columnsObject (readonly)

Returns the value of attribute columns.



5
6
7
# File 'lib/table_help/table_for.rb', line 5

def columns
  @columns
end

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/table_help/table_for.rb', line 5

def context
  @context
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/table_help/table_for.rb', line 5

def options
  @options
end

#qObject (readonly)

Returns the value of attribute q.



5
6
7
# File 'lib/table_help/table_for.rb', line 5

def q
  @q
end

#strategiesObject (readonly)

Returns the value of attribute strategies.



5
6
7
# File 'lib/table_help/table_for.rb', line 5

def strategies
  @strategies
end

Instance Method Details

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



17
18
19
20
# File 'lib/table_help/table_for.rb', line 17

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

#to_htmlObject



22
23
24
25
26
27
28
29
# File 'lib/table_help/table_for.rb', line 22

def to_html
  return if collection.empty?

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