columnize 0.3.0 → 0.3.1
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 +26 -0
- data/NEWS +7 -1
- data/Rakefile +18 -3
- data/VERSION +1 -1
- data/lib/columnize.rb +26 -15
- data/test/test-columnize.rb +11 -0
- metadata +64 -33
data/ChangeLog
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
2009-07-26 23:16 rockyb
|
2
|
+
|
3
|
+
* ChangeLog: Get ready for 0.3.1 release
|
4
|
+
|
5
|
+
2009-07-26 23:13 rockyb
|
6
|
+
|
7
|
+
* NEWS, lib/columnize.rb, test/test-columnize.rb: Add lineprefix.
|
8
|
+
Get ready for release.
|
9
|
+
|
10
|
+
2009-07-26 21:59 mark-moseley
|
11
|
+
|
12
|
+
* ChangeLog, lib/columnize.rb: Ruby 1.9 updates
|
13
|
+
|
14
|
+
2009-03-30 08:54 rockyb
|
15
|
+
|
16
|
+
* Rakefile: Revise for 1.9 version of rake
|
17
|
+
|
18
|
+
2009-01-16 18:32 rockyb
|
19
|
+
|
20
|
+
* ChangeLog, Rakefile, VERSION: package readme was wonky. Looks
|
21
|
+
like no one reads this stuff.
|
22
|
+
|
23
|
+
2009-01-10 19:02 rockyb
|
24
|
+
|
25
|
+
* ChangeLog, NEWS: Get ready for release
|
26
|
+
|
1
27
|
2009-01-08 09:27 rockyb
|
2
28
|
|
3
29
|
* ChangeLog, NEWS, VERSION, lib/columnize.rb,
|
data/NEWS
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.3.1 (01-07-26)
|
2
|
+
|
3
|
+
- Correct for Ruby 1.9 (Mark Mosely)
|
4
|
+
|
5
|
+
- add optional lineprefix parameter
|
6
|
+
|
1
7
|
0.3.0 (01-10-09) - Sam Woodward Release
|
2
8
|
|
3
9
|
- Fix bad bug in arranging horizontally
|
@@ -15,4 +21,4 @@
|
|
15
21
|
- Initial release of Columnize, a module to print an Array in
|
16
22
|
column-sorted order
|
17
23
|
|
18
|
-
$Id: NEWS
|
24
|
+
$Id: NEWS 173 2009-07-26 23:13:54Z rockyb $
|
data/Rakefile
CHANGED
@@ -25,7 +25,7 @@ FILES = FileList[
|
|
25
25
|
desc "Test everything."
|
26
26
|
test_task = task :test => :lib do
|
27
27
|
Rake::TestTask.new(:test) do |t|
|
28
|
-
t.libs <<
|
28
|
+
t.libs << './lib'
|
29
29
|
t.pattern = 'test/test-*.rb'
|
30
30
|
t.verbose = true
|
31
31
|
end
|
@@ -46,8 +46,23 @@ default_spec = Gem::Specification.new do |spec|
|
|
46
46
|
spec.homepage = "http://rubyforge.org/projects/rocky-hacks/columnize"
|
47
47
|
spec.summary = "Read file with caching"
|
48
48
|
spec.description = <<-EOF
|
49
|
-
|
50
|
-
|
49
|
+
Return a list of strings as a set of arranged in columns.
|
50
|
+
|
51
|
+
For example, for a line width of 4 characters (arranged vertically):
|
52
|
+
['1', '2,', '3', '4'] => '1 3\n2 4\n'
|
53
|
+
|
54
|
+
or arranged horizontally:
|
55
|
+
['1', '2,', '3', '4'] => '1 2\n3 4\n'
|
56
|
+
|
57
|
+
Each column is only as wide as necessary. By default, columns are
|
58
|
+
separated by two spaces - one was not legible enough. Set "colsep"
|
59
|
+
to adjust the string separate columns. Set `displaywidth' to set
|
60
|
+
the line width.
|
61
|
+
|
62
|
+
Normally, consecutive items go down from the top to bottom from
|
63
|
+
the left-most column to the right-most. If +arrange_vertical+ is
|
64
|
+
set false, consecutive items will go across, left to right, top to
|
65
|
+
bottom.
|
51
66
|
EOF
|
52
67
|
|
53
68
|
spec.version = PACKAGE_VERSION
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/columnize.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: columnize.rb
|
1
|
+
# $Id: columnize.rb 175 2009-07-26 23:24:40Z rockyb $
|
2
2
|
#
|
3
3
|
# Copyright (C) 2007, 2008, 2009 Rocky Bernstein <rockyb@rubyforge.net>
|
4
4
|
#
|
@@ -37,7 +37,7 @@
|
|
37
37
|
|
38
38
|
module Columnize
|
39
39
|
|
40
|
-
# Return a list of strings with
|
40
|
+
# Return a list of strings with embedded newlines (\n) as a compact
|
41
41
|
# set of columns arranged horizontally or vertically.
|
42
42
|
#
|
43
43
|
# For example, for a line width of 4 characters (arranged vertically):
|
@@ -54,7 +54,7 @@ module Columnize
|
|
54
54
|
# will go across, left to right, top to bottom.
|
55
55
|
|
56
56
|
def columnize(list, displaywidth=80, colsep = ' ',
|
57
|
-
arrange_vertical=true, ljust=true)
|
57
|
+
arrange_vertical=true, ljust=true, lineprefix='')
|
58
58
|
|
59
59
|
# Some degenerate cases
|
60
60
|
if not list.is_a?(Array)
|
@@ -70,18 +70,22 @@ module Columnize
|
|
70
70
|
|
71
71
|
nrows = ncols = 0 # Make nrows, ncols have more global scope
|
72
72
|
colwidths = [] # Same for colwidths
|
73
|
+
displaywidth = [4, displaywidth - lineprefix.length].max
|
73
74
|
if arrange_vertical
|
74
75
|
array_index = lambda {|nrows, row, col| nrows*col + row }
|
75
76
|
# Try every row count from 1 upwards
|
76
|
-
1.upto(l.size-1) do |
|
77
|
+
1.upto(l.size-1) do |_nrows|
|
78
|
+
nrows = _nrows
|
77
79
|
ncols = (l.size + nrows-1) / nrows
|
78
80
|
colwidths = []
|
79
81
|
totwidth = -colsep.length
|
80
82
|
|
81
|
-
0.upto(ncols-1) do |
|
83
|
+
0.upto(ncols-1) do |_col|
|
84
|
+
col = _col
|
82
85
|
# get max column width for this column
|
83
86
|
colwidth = 0
|
84
|
-
0.upto(nrows-1) do |
|
87
|
+
0.upto(nrows-1) do |_row|
|
88
|
+
row = _row
|
85
89
|
i = array_index.call(nrows, row, col)
|
86
90
|
if i >= l.size
|
87
91
|
break
|
@@ -104,9 +108,11 @@ module Columnize
|
|
104
108
|
# Now we just have to format each of the
|
105
109
|
# rows.
|
106
110
|
s = ''
|
107
|
-
0.upto(nrows-1) do |
|
111
|
+
0.upto(nrows-1) do |_row|
|
112
|
+
row = _row
|
108
113
|
texts = []
|
109
|
-
0.upto(ncols-1) do |
|
114
|
+
0.upto(ncols-1) do |_col|
|
115
|
+
col = _col
|
110
116
|
i = array_index.call(nrows, row, col)
|
111
117
|
if i >= l.size
|
112
118
|
x = ""
|
@@ -119,14 +125,15 @@ module Columnize
|
|
119
125
|
texts = texts[0..-2]
|
120
126
|
end
|
121
127
|
if texts.size > 0
|
122
|
-
0.upto(texts.size-1) do |
|
128
|
+
0.upto(texts.size-1) do |_col|
|
129
|
+
col = _col
|
123
130
|
if ljust
|
124
131
|
texts[col] = texts[col].ljust(colwidths[col])
|
125
132
|
else
|
126
133
|
texts[col] = texts[col].rjust(colwidths[col])
|
127
134
|
end
|
128
135
|
end
|
129
|
-
s += "%s\n" % texts.join(colsep)
|
136
|
+
s += "%s%s\n" % [lineprefix, texts.join(colsep)]
|
130
137
|
end
|
131
138
|
end
|
132
139
|
return s
|
@@ -135,17 +142,21 @@ module Columnize
|
|
135
142
|
# Try every column count from size downwards
|
136
143
|
# Assign to make enlarge scope of loop variables
|
137
144
|
totwidth = i = rounded_size = 0
|
138
|
-
l.size.downto(0) do |
|
145
|
+
l.size.downto(0) do |_ncols|
|
146
|
+
ncols = _ncols
|
139
147
|
# Try every row count from 1 upwards
|
140
148
|
min_rows = (l.size+ncols-1) / ncols
|
141
|
-
min_rows.upto(l.size) do |
|
149
|
+
min_rows.upto(l.size) do |_nrows|
|
150
|
+
nrows = _nrows
|
142
151
|
rounded_size = nrows * ncols
|
143
152
|
colwidths = []
|
144
153
|
totwidth = -colsep.length
|
145
154
|
colwidth = row = 0
|
146
|
-
0.upto(ncols-1) do |
|
155
|
+
0.upto(ncols-1) do |_col|
|
156
|
+
col = _col
|
147
157
|
# get max column width for this column
|
148
|
-
1.upto(nrows) do |
|
158
|
+
1.upto(nrows) do |_row|
|
159
|
+
row = _row
|
149
160
|
i = array_index.call(nrows, row, col)
|
150
161
|
if i >= rounded_size
|
151
162
|
break
|
@@ -195,7 +206,7 @@ module Columnize
|
|
195
206
|
texts[col] = texts[col].rjust(colwidths[col])
|
196
207
|
end
|
197
208
|
end
|
198
|
-
s += "%s\n" % texts.join(colsep)
|
209
|
+
s += "%s%s\n" % [lineprefix, texts.join(colsep)]
|
199
210
|
end
|
200
211
|
return s
|
201
212
|
end
|
data/test/test-columnize.rb
CHANGED
@@ -43,6 +43,17 @@ class TestColumnize < Test::Unit::TestCase
|
|
43
43
|
columnize(data, 39, ', ', false, false))
|
44
44
|
|
45
45
|
|
46
|
+
assert_equal(
|
47
|
+
" 0, 1, 2, 3, 4, 5, 6, 7, 8\n" +
|
48
|
+
" 9, 10, 11, 12, 13, 14, 15, 16, 17\n" +
|
49
|
+
" 18, 19, 20, 21, 22, 23, 24, 25, 26\n" +
|
50
|
+
" 27, 28, 29, 30, 31, 32, 33, 34, 35\n" +
|
51
|
+
" 36, 37, 38, 39, 40, 41, 42, 43, 44\n" +
|
52
|
+
" 45, 46, 47, 48, 49, 50, 51, 52, 53\n" +
|
53
|
+
" 54\n",
|
54
|
+
columnize(data, 39, ', ', false, false, ' '))
|
55
|
+
|
56
|
+
|
46
57
|
data = ["one", "two", "three",
|
47
58
|
"for", "five", "six",
|
48
59
|
"seven", "eight", "nine",
|
metadata
CHANGED
@@ -1,33 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: columnize
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.3.
|
7
|
-
date: 2009-01-10 00:00:00 -05:00
|
8
|
-
summary: Read file with caching
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: rockyb@rubyforge.net
|
12
|
-
homepage: http://rubyforge.org/projects/rocky-hacks/columnize
|
13
|
-
rubyforge_project: rocky-hacks
|
14
|
-
description: Columnize is a module for reading and caching lines. This may be useful for example in a debugger where the same lines are shown many times.
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.8.2
|
24
|
-
version:
|
4
|
+
version: 0.3.1
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- R. Bernstein
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-26 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: |
|
17
|
+
Return a list of strings as a set of arranged in columns.
|
18
|
+
|
19
|
+
For example, for a line width of 4 characters (arranged vertically):
|
20
|
+
['1', '2,', '3', '4'] => '1 3
|
21
|
+
2 4
|
22
|
+
'
|
23
|
+
|
24
|
+
or arranged horizontally:
|
25
|
+
['1', '2,', '3', '4'] => '1 2
|
26
|
+
3 4
|
27
|
+
'
|
28
|
+
|
29
|
+
Each column is only as wide as necessary. By default, columns are
|
30
|
+
separated by two spaces - one was not legible enough. Set "colsep"
|
31
|
+
to adjust the string separate columns. Set `displaywidth' to set
|
32
|
+
the line width.
|
33
|
+
|
34
|
+
Normally, consecutive items go down from the top to bottom from
|
35
|
+
the left-most column to the right-most. If +arrange_vertical+ is
|
36
|
+
set false, consecutive items will go across, left to right, top to
|
37
|
+
bottom.
|
38
|
+
|
39
|
+
email: rockyb@rubyforge.net
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README
|
46
|
+
- lib/columnize.rb
|
31
47
|
files:
|
32
48
|
- AUTHORS
|
33
49
|
- COPYING
|
@@ -38,18 +54,33 @@ files:
|
|
38
54
|
- VERSION
|
39
55
|
- lib/columnize.rb
|
40
56
|
- test/test-columnize.rb
|
41
|
-
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://rubyforge.org/projects/rocky-hacks/columnize
|
59
|
+
licenses: []
|
42
60
|
|
61
|
+
post_install_message:
|
43
62
|
rdoc_options: []
|
44
63
|
|
45
|
-
|
46
|
-
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.8.2
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
52
78
|
requirements: []
|
53
79
|
|
54
|
-
|
80
|
+
rubyforge_project: rocky-hacks
|
81
|
+
rubygems_version: 1.3.4
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Read file with caching
|
85
|
+
test_files: []
|
55
86
|
|