Class: Daru::Formatters::Table
Class Method Summary collapse
Instance Method Summary collapse
- #format(threshold = nil, spacing = nil) ⇒ Object
-
#initialize(data, headers, row_headers) ⇒ Table
constructor
A new instance of Table.
Constructor Details
#initialize(data, headers, row_headers) ⇒ Table
Returns a new instance of Table.
9 10 11 12 13 14 |
# File 'lib/daru/formatters/table.rb', line 9 def initialize(data, headers, row_headers) @data = data || [] @headers = (headers || []).to_a @row_headers = (row_headers || []).to_a @row_headers = [''] * @data.to_a.size if @row_headers.empty? end |
Class Method Details
.format(data, options = {}) ⇒ Object
4 5 6 7 |
# File 'lib/daru/formatters/table.rb', line 4 def self.format data, ={} new(data, [:headers], [:row_headers]) .format([:threshold], [:spacing]) end |
Instance Method Details
#format(threshold = nil, spacing = nil) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/daru/formatters/table.rb', line 16 def format threshold=nil, spacing=nil rows = build_rows(threshold || Daru.max_rows) formatter = construct_formatter rows, spacing || Daru.spacing rows.map { |r| formatter % r }.join("\n") end |