12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/format_array.rb', line 12
def format_array(a, p, cutoff=120, j='; ')
raw = a.sort.join(j)
tmp = "#{p}: #{raw}"
if raw.length + p.length < cutoff then
return [tmp]
end
lines = raw.length / cutoff
sa = a.sort_by {|s| s.length}.reverse
out = Array.new(12) { Array.new } while (sa.length > lines+1) do
0.upto(lines) { |i|
out[i].push sa.shift
}
end
0.upto(sa.length-1) { |i|
out[i].push sa.shift
}
strings = out.find_all {|i| i.length > 0}.map {|i| "#{p}: " << i.join(j)}
return strings
end
|