Class: Arrow::TableFormatter
- Inherits:
-
Object
- Object
- Arrow::TableFormatter
- Defined in:
- lib/arrow/table-formatter.rb
Overview
TODO: Almost codes should be implemented in Apache Arrow C++.
Direct Known Subclasses
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(table, options = {}) ⇒ TableFormatter
constructor
A new instance of TableFormatter.
Constructor Details
#initialize(table, options = {}) ⇒ TableFormatter
Returns a new instance of TableFormatter.
21 22 23 24 |
# File 'lib/arrow/table-formatter.rb', line 21 def initialize(table, ={}) @table = table @options = end |
Instance Method Details
#format ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/arrow/table-formatter.rb', line 26 def format text = "" columns = @table.columns format_header(text, columns) n_rows = @table.n_rows return text if n_rows.zero? border = @options[:border] || 10 n_digits = (Math.log10(n_rows) + 1).truncate head_limit = [border, n_rows].min head_column_values = columns.collect do |column| column.each.take(head_limit) end format_rows(text, columns, head_column_values.transpose, n_digits, 0) return text if n_rows <= border tail_start = [border, n_rows - border].max tail_limit = n_rows - tail_start tail_column_values = columns.collect do |column| column.reverse_each.take(tail_limit).reverse end if head_limit != tail_start format_ellipsis(text) end format_rows(text, columns, tail_column_values.transpose, n_digits, tail_start) text end |