Class: Hirb::Helpers::ObjectTable

Inherits:
Table
  • Object
show all
Defined in:
lib/hirb/helpers/object_table.rb

Direct Known Subclasses

ActiveRecordTable

Constant Summary

Constants inherited from Table

Table::BORDER_LENGTH

Class Method Summary collapse

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, options ={})
  options[:fields] ||= [:to_s]
  options[:headers] = {:to_s=>'value'} if options[:fields] == [:to_s]
  rows = [rows] unless rows.is_a?(Array)
  item_hashes = rows.inject([]) {|t,item|
    t << options[:fields].inject({}) {|h,f| h[f] = item.send(f); h}
  }
  super(item_hashes, options)
end