Class: HtmlTable::TableRowBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/html_table/table_row_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) {|_self| ... } ⇒ TableRowBuilder

Returns a new instance of TableRowBuilder.

Yields:

  • (_self)

Yield Parameters:



4
5
6
7
8
9
# File 'lib/html_table/table_row_builder.rb', line 4

def initialize(object)
  @object = object
  @columns = []
  @html_columns = []
  yield(self)
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



2
3
4
# File 'lib/html_table/table_row_builder.rb', line 2

def columns
  @columns
end

#html_columnsObject

Returns the value of attribute html_columns.



2
3
4
# File 'lib/html_table/table_row_builder.rb', line 2

def html_columns
  @html_columns
end

#objectObject (readonly)

Returns the value of attribute object.



3
4
5
# File 'lib/html_table/table_row_builder.rb', line 3

def object
  @object
end

Instance Method Details

#column(column_name, *args) ⇒ Object



15
16
17
18
19
20
# File 'lib/html_table/table_row_builder.rb', line 15

def column column_name, *args
  options = args.extract_options!
  columns << column_name
  html_columns << "<td>#{value(column_name, options)}</td>"
  html_columns.last
end

#to_sObject



11
12
13
# File 'lib/html_table/table_row_builder.rb', line 11

def to_s
  "<tr>#{html_columns}</tr>"
end

#value(column_name, options) ⇒ Object



22
23
24
# File 'lib/html_table/table_row_builder.rb', line 22

def value column_name, options
  options[:value] || column_name && object.send(column_name)
end