Class: Daru::Formatters::Table
Constant Summary collapse
- DEFAULT_SPACING =
10
- DEFAULT_THRESHOLD =
15
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
19 20 21 22 23 24 25 |
# File 'lib/daru/formatters/table.rb', line 19 def format threshold=nil, spacing=nil rows = build_rows(threshold || DEFAULT_THRESHOLD) formatter = construct_formatter rows, spacing || DEFAULT_SPACING rows.map { |r| formatter % r }.join("\n") end |