lib/reportly/engine.rb in reportly-0.0.1 vs lib/reportly/engine.rb in reportly-0.0.2

- old
+ new

@@ -10,22 +10,25 @@ len = item.read_attribute(field).to_s.length max_len[field] = len if len > max_len[field] end end + report = [] + border = '+-' + fields.map {|f| '-' * max_len[f] }.join('-+-') + '-+' title_row = '| ' + fields.map {|f| sprintf("%-#{max_len[f]}s", f.to_s) }.join(' | ') + ' |' - puts border - puts title_row - puts border + report << border + report << title_row + report << border items.each do |item| row = '| ' + fields.map {|f| sprintf("%-#{max_len[f]}s", item.read_attribute(f)) }.join(' | ') + ' |' - puts row + report << row end - puts border - puts "#{items.length} rows in set\n" + report << border + report << "#{items.length} rows in set" + report end end end