format_array 1.1 → 1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +2 -0
- data/format_array.gemspec +1 -1
- data/lib/format_array.rb +12 -3
- metadata +3 -3
data/CHANGELOG
CHANGED
data/format_array.gemspec
CHANGED
data/lib/format_array.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
-
|
1
|
+
# = format_array.rb
|
2
|
+
#
|
3
|
+
# == Example
|
4
|
+
#
|
5
|
+
# require 'format_array'
|
6
|
+
# # default cutoff is 120 characters
|
7
|
+
# format_array(['list','of','things'], 'PREFIX')
|
8
|
+
#
|
9
|
+
# # we can specify our own, say 76
|
10
|
+
# format_array(['list','of','things'], 'PREFIX', 76)
|
2
11
|
|
3
|
-
def format_array(a, p, cutoff=
|
12
|
+
def format_array(a, p, cutoff=120, j='; ')
|
4
13
|
raw = a.sort.join(j)
|
5
14
|
tmp = "#{p}: #{raw}"
|
6
15
|
|
@@ -12,7 +21,7 @@ def format_array(a, p, cutoff=CUTOFF, j='; ')
|
|
12
21
|
# try a naive longest->shortest distribution
|
13
22
|
lines = raw.length / cutoff
|
14
23
|
sa = a.sort_by {|s| s.length}.reverse
|
15
|
-
out = Array.new(12) { Array.new }
|
24
|
+
out = Array.new(12) { Array.new } # what does magic 12 mean?
|
16
25
|
while (sa.length > lines+1) do
|
17
26
|
0.upto(lines) { |i|
|
18
27
|
out[i].push sa.shift
|
metadata
CHANGED