76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/collins/cli/formatter.rb', line 76
def display_as_table(assets, columns, separator, = false)
column_width_pairs = columns.map do |column|
width = assets.map{|a| (column == :state) ? a.send(column).label.to_s.length : a.send(column).to_s.length}.max
width = [width, column.to_s.length].max if
[column,width]
end
column_width_map = Hash[column_width_pairs]
if
$stderr.puts column_width_map.map{|c,w| "%-#{w}s" % c}.join(separator)
end
assets.each do |a|
puts column_width_map.map {|c,w| v = (c == :state) ? a.send(c).label : a.send(c) ; "%-#{w}s" % v }.join(separator)
end
end
|