Class: Rotulus::PageTableizer
- Inherits:
-
Object
- Object
- Rotulus::PageTableizer
- Defined in:
- lib/rotulus/page_tableizer.rb
Instance Method Summary collapse
-
#initialize(page) ⇒ PageTableizer
constructor
A new instance of PageTableizer.
-
#tableize ⇒ String
Returns a string showing the page’s records in table form with the ordered columns as the columns.
Constructor Details
#initialize(page) ⇒ PageTableizer
3 4 5 |
# File 'lib/rotulus/page_tableizer.rb', line 3 def initialize(page) @page = page end |
Instance Method Details
#tableize ⇒ String
Returns a string showing the page’s records in table form with the ordered columns as the columns. Some data types are formatted so output is consistent regardless of the DB engine in use:
1. Datetime - iso8601(3) formatted
2. Float - converted to BigDecimal before converting to string
3. Float/BigDecimal - '.0' fractional portion is dropped
4. Nil - <NULL>
example:
+-----------------------------------------------------------------------------------------+
| users.first_name | users.last_name | users.email | users.id |
+-----------------------------------------------------------------------------------------+
| George | <NULL> | [email protected] | 1 |
| Jane | Smith | [email protected] | 2 |
| Jane | Doe | [email protected] | 3 |
+-----------------------------------------------------------------------------------------+
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rotulus/page_tableizer.rb', line 26 def tableize return '' if records.blank? s = '' s << divider s << header s << divider s << records.map { |record| record_to_string(record) }.join("\n") s << "\n" s << divider s end |