Class: Cardigan::TextReportFormatter
- Inherits:
-
Object
- Object
- Cardigan::TextReportFormatter
- Defined in:
- lib/cardigan/text_report_formatter.rb
Constant Summary collapse
- INDEX_HEADING =
'index'
Instance Method Summary collapse
- #add_column(name, length) ⇒ Object
-
#initialize(io) ⇒ TextReportFormatter
constructor
A new instance of TextReportFormatter.
- #output(hashes, options = {}) ⇒ Object
Constructor Details
#initialize(io) ⇒ TextReportFormatter
Returns a new instance of TextReportFormatter.
5 6 7 8 |
# File 'lib/cardigan/text_report_formatter.rb', line 5 def initialize io @io = io @columns = [] end |
Instance Method Details
#add_column(name, length) ⇒ Object
10 11 12 13 |
# File 'lib/cardigan/text_report_formatter.rb', line 10 def add_column name, length longer = [name.length, length].max @columns << [name, longer] end |
#output(hashes, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cardigan/text_report_formatter.rb', line 15 def output hashes, ={} return if @columns.empty? width = calculate_width([:suppress_index]) hline width row INDEX_HEADING, @columns.map {|tuple| tuple.first }, [:suppress_index] hline width hashes.each_with_index do |h,i| row (i+1).to_s, @columns.map {|tuple| h[tuple.first]}, [:suppress_index] end hline width end |