module PrintUtils
Print Utilities
Public Instance Methods
asTable(args, col_width = 15, title = '', show_idx = true)
click to toggle source
Printable tabular String
representation of args data @param args [[[object]]] Table Data @param col_width [Integer] Column Width @param title [String] Table Title @param show_idx [Bool] Show Index? @return [String] Table String
# File lib/hoopscrape/PrintUtils.rb, line 9 def asTable(args, col_width = 15, title = '', show_idx = true) result = "\n#{title}" idx_width = args.size.to_s.length args.each_with_index do |row, idx| result << "\n#{idx + 1}." + ' ' * pad(idx_width, idx) + ' ' if show_idx result << "\n" unless show_idx formatRow(row, col_width, result) end result << "\n" end
Private Instance Methods
formatRow(row, width, target)
click to toggle source
Format Row
# File lib/hoopscrape/PrintUtils.rb, line 23 def formatRow(row, width, target) row.each do |td| target << td.to_s target << ' ' * pad(width, td) if pad(width, td) > 0 end end
pad(width, content)
click to toggle source
Calculate required padding
# File lib/hoopscrape/PrintUtils.rb, line 31 def pad(width, content) (width - content.to_s.length) > 0 ? (width - content.to_s.length) : 0 end