Class: Hirb::Helpers::ObjectTable
- Defined in:
- lib/hirb/helpers/object_table.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Table
Class Method Summary collapse
-
.render(rows, options = {}) ⇒ Object
Rows are any ruby objects.
Methods inherited from Table
#adjust_long_fields, #array_to_indices_hash, #default_field_lengths, #default_restrict_field_lengths, #filter_values, #format_cell, #initialize, #render, #render_border, #render_footer, #render_header, #render_rows, #render_table_description, #render_table_header, #restrict_field_lengths, #set_fields, #setup_field_lengths, #setup_rows, #validate_values
Constructor Details
This class inherits a constructor from Hirb::Helpers::Table
Class Method Details
.render(rows, options = {}) ⇒ Object
Rows are any ruby objects. Takes same options as Hirb::Helpers::Table.render except as noted below.
Options:
:fields- Methods of the object to represent as columns. Defaults to [:to_s].
6 7 8 9 10 11 12 13 14 |
# File 'lib/hirb/helpers/object_table.rb', line 6 def self.render(rows, ={}) [:fields] ||= [:to_s] [:headers] = {:to_s=>'value'} if [:fields] == [:to_s] rows = [rows] unless rows.is_a?(Array) item_hashes = rows.inject([]) {|t,item| t << [:fields].inject({}) {|h,f| h[f] = item.send(f); h} } super(item_hashes, ) end |