Class: Rotulus::PageTableizer

Inherits:
Object
  • Object
show all
Defined in:
lib/rotulus/page_tableizer.rb

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ PageTableizer

Returns a new instance of PageTableizer.



3
4
5
# File 'lib/rotulus/page_tableizer.rb', line 3

def initialize(page)
  @page = page
end

Instance Method Details

#tableizeString

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>        |     george@domain.com      |      1        |
|         Jane         |        Smith        |   jane.c.smith@email.com   |      2        |
|         Jane         |         Doe         |     jane.doe@email.com     |      3        |
+-----------------------------------------------------------------------------------------+

Returns:

  • (String)

    table



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