Class: Hirb::Helpers::ObjectTable
- Defined in:
- lib/hirb/helpers/object_table.rb
Constant Summary
Constants inherited from Table
Table::BORDER_LENGTH, Table::CHARS, Table::MIN_FIELD_LENGTH
Instance Attribute Summary
Attributes inherited from Table
#field_lengths, #fields, #max_fields, #width
Class Method Summary collapse
-
.render(rows, options = {}) ⇒ Object
Rows are any ruby objects.
Methods inherited from Table
#actual_width, #array_to_indices_hash, #call_filter, #chars, #default_field_lengths, #enforce_field_constraints, #filter_values, #format_cell, #format_values, #initialize, #render, #render_border, #render_footer, #render_header, #render_rows, #render_table_description, #render_table_header, #set_fields, #set_filter_defaults, #set_headers, #set_rows, #setup_field_lengths, #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 |
# File 'lib/hirb/helpers/object_table.rb', line 6 def self.render(rows, ={}) [:fields] ||= [:to_s] [:headers] ||= {:to_s=>'value'} if [:fields] == [:to_s] item_hashes = [:fields].empty? ? [] : Array(rows).inject([]) {|t,item| t << [:fields].inject({}) {|h,f| h[f] = item.__send__(f); h} } super(item_hashes, ) end |