Module: ZTK::Report::Private
- Included in:
- ZTK::Report
- Defined in:
- lib/ztk/report/private.rb
Overview
Report Private Functionality
Instance Method Summary (collapse)
- - (Object) calculate_spreadsheet_width(headers, max_lengths)
- - (Object) format_entry(key, key_length, value, value_length)
- - (Object) format_header(headers, lengths)
- - (Object) format_row(*args)
- - (Object) max_spreadsheet_lengths(headers, rows)
Instance Method Details
- (Object) calculate_spreadsheet_width(headers, max_lengths)
18 19 20 21 22 |
# File 'lib/ztk/report/private.rb', line 18 def calculate_spreadsheet_width(headers, max_lengths) header_lengths = ((headers.count * 3) - 3) max_length = (max_lengths.send(:table) rescue max_lengths).values.reduce(:+) (2 + max_length + header_lengths + 2) end |
- (Object) format_entry(key, key_length, value, value_length)
37 38 39 |
# File 'lib/ztk/report/private.rb', line 37 def format_entry(key, key_length, value, value_length) "| %#{key_length}s: %-#{value_length}s |" % [key.to_s.upcase, value.to_s] end |
- (Object) format_header(headers, lengths)
24 25 26 27 28 29 30 |
# File 'lib/ztk/report/private.rb', line 24 def format_header(headers, lengths) line = headers.collect do |header| "-" * (lengths.send(:table) rescue lengths)[header] end ["+-", line.join("-+-"), "-+"].join.strip end |
- (Object) format_row(*args)
32 33 34 35 |
# File 'lib/ztk/report/private.rb', line 32 def format_row(*args) spacer = " " [spacer, args, spacer].flatten.join(" | ").strip end |
- (Object) max_spreadsheet_lengths(headers, rows)
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ztk/report/private.rb', line 7 def max_spreadsheet_lengths(headers, rows) max_lengths = OpenStruct.new headers.each do |header| collection = [header, rows.collect{|r| (r.send(:table) rescue r)[header] } ].flatten maximum = collection.map(&:to_s).map(&:length).max (max_lengths.send(:table) rescue max_lengths)[header] = maximum end max_lengths end |