columnize 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ /pkg
data/COPYING CHANGED
@@ -1,340 +1,57 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 2, June 1991
1
+ Columnize is copyrighted free software by Rocky Bernstein <rocky@rubyforge.org>.
3
2
 
4
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
- Everyone is permitted to copy and distribute verbatim copies
7
- of this license document, but changing it is not allowed.
3
+ You can redistribute it and/or modify it under either the terms of the GPL
4
+ version 2 (see the file GPL), or the conditions below:
8
5
 
9
- Preamble
6
+ 1. You may make and give away verbatim copies of the source form of the
7
+ software without restriction, provided that you duplicate all of the
8
+ original copyright notices and associated disclaimers.
10
9
 
11
- The licenses for most software are designed to take away your
12
- freedom to share and change it. By contrast, the GNU General Public
13
- License is intended to guarantee your freedom to share and change free
14
- software--to make sure the software is free for all its users. This
15
- General Public License applies to most of the Free Software
16
- Foundation's software and to any other program whose authors commit to
17
- using it. (Some other Free Software Foundation software is covered by
18
- the GNU Library General Public License instead.) You can apply it to
19
- your programs, too.
10
+ 2. You may modify your copy of the software in any way, provided that
11
+ you do at least ONE of the following:
20
12
 
21
- When we speak of free software, we are referring to freedom, not
22
- price. Our General Public Licenses are designed to make sure that you
23
- have the freedom to distribute copies of free software (and charge for
24
- this service if you wish), that you receive source code or can get it
25
- if you want it, that you can change the software or use pieces of it
26
- in new free programs; and that you know you can do these things.
13
+ a) place your modifications in the Public Domain or otherwise
14
+ make them Freely Available, such as by posting said
15
+ modifications to Usenet or an equivalent medium, or by allowing
16
+ the author to include your modifications in the software.
27
17
 
28
- To protect your rights, we need to make restrictions that forbid
29
- anyone to deny you these rights or to ask you to surrender the rights.
30
- These restrictions translate to certain responsibilities for you if you
31
- distribute copies of the software, or if you modify it.
18
+ b) use the modified software only within your corporation or
19
+ organization.
32
20
 
33
- For example, if you distribute copies of such a program, whether
34
- gratis or for a fee, you must give the recipients all the rights that
35
- you have. You must make sure that they, too, receive or can get the
36
- source code. And you must show them these terms so they know their
37
- rights.
21
+ c) give non-standard binaries non-standard names, with
22
+ instructions on where to get the original software distribution.
38
23
 
39
- We protect your rights with two steps: (1) copyright the software, and
40
- (2) offer you this license which gives you legal permission to copy,
41
- distribute and/or modify the software.
24
+ d) make other distribution arrangements with the author.
42
25
 
43
- Also, for each author's protection and ours, we want to make certain
44
- that everyone understands that there is no warranty for this free
45
- software. If the software is modified by someone else and passed on, we
46
- want its recipients to know that what they have is not the original, so
47
- that any problems introduced by others will not reflect on the original
48
- authors' reputations.
26
+ 3. You may distribute the software in object code or binary form,
27
+ provided that you do at least ONE of the following:
49
28
 
50
- Finally, any free program is threatened constantly by software
51
- patents. We wish to avoid the danger that redistributors of a free
52
- program will individually obtain patent licenses, in effect making the
53
- program proprietary. To prevent this, we have made it clear that any
54
- patent must be licensed for everyone's free use or not licensed at all.
29
+ a) distribute the binaries and library files of the software,
30
+ together with instructions (in the manual page or equivalent)
31
+ on where to get the original distribution.
55
32
 
56
- The precise terms and conditions for copying, distribution and
57
- modification follow.
58
-
59
- GNU GENERAL PUBLIC LICENSE
60
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
33
+ b) accompany the distribution with the machine-readable source of
34
+ the software.
61
35
 
62
- 0. This License applies to any program or other work which contains
63
- a notice placed by the copyright holder saying it may be distributed
64
- under the terms of this General Public License. The "Program", below,
65
- refers to any such program or work, and a "work based on the Program"
66
- means either the Program or any derivative work under copyright law:
67
- that is to say, a work containing the Program or a portion of it,
68
- either verbatim or with modifications and/or translated into another
69
- language. (Hereinafter, translation is included without limitation in
70
- the term "modification".) Each licensee is addressed as "you".
36
+ c) give non-standard binaries non-standard names, with
37
+ instructions on where to get the original software distribution.
71
38
 
72
- Activities other than copying, distribution and modification are not
73
- covered by this License; they are outside its scope. The act of
74
- running the Program is not restricted, and the output from the Program
75
- is covered only if its contents constitute a work based on the
76
- Program (independent of having been made by running the Program).
77
- Whether that is true depends on what the Program does.
39
+ d) make other distribution arrangements with the author.
78
40
 
79
- 1. You may copy and distribute verbatim copies of the Program's
80
- source code as you receive it, in any medium, provided that you
81
- conspicuously and appropriately publish on each copy an appropriate
82
- copyright notice and disclaimer of warranty; keep intact all the
83
- notices that refer to this License and to the absence of any warranty;
84
- and give any other recipients of the Program a copy of this License
85
- along with the Program.
41
+ 4. You may modify and include the part of the software into any other
42
+ software (possibly commercial). But some files in the distribution
43
+ are not written by the author, so that they are not under these terms.
86
44
 
87
- You may charge a fee for the physical act of transferring a copy, and
88
- you may at your option offer warranty protection in exchange for a fee.
45
+ For the list of those files and their copying conditions, see the
46
+ file LEGAL.
89
47
 
90
- 2. You may modify your copy or copies of the Program or any portion
91
- of it, thus forming a work based on the Program, and copy and
92
- distribute such modifications or work under the terms of Section 1
93
- above, provided that you also meet all of these conditions:
48
+ 5. The scripts and library files supplied as input to or produced as
49
+ output from the software do not automatically fall under the
50
+ copyright of the software, but belong to whomever generated them,
51
+ and may be sold commercially, and may be aggregated with this
52
+ software.
94
53
 
95
- a) You must cause the modified files to carry prominent notices
96
- stating that you changed the files and the date of any change.
97
-
98
- b) You must cause any work that you distribute or publish, that in
99
- whole or in part contains or is derived from the Program or any
100
- part thereof, to be licensed as a whole at no charge to all third
101
- parties under the terms of this License.
102
-
103
- c) If the modified program normally reads commands interactively
104
- when run, you must cause it, when started running for such
105
- interactive use in the most ordinary way, to print or display an
106
- announcement including an appropriate copyright notice and a
107
- notice that there is no warranty (or else, saying that you provide
108
- a warranty) and that users may redistribute the program under
109
- these conditions, and telling the user how to view a copy of this
110
- License. (Exception: if the Program itself is interactive but
111
- does not normally print such an announcement, your work based on
112
- the Program is not required to print an announcement.)
113
-
114
- These requirements apply to the modified work as a whole. If
115
- identifiable sections of that work are not derived from the Program,
116
- and can be reasonably considered independent and separate works in
117
- themselves, then this License, and its terms, do not apply to those
118
- sections when you distribute them as separate works. But when you
119
- distribute the same sections as part of a whole which is a work based
120
- on the Program, the distribution of the whole must be on the terms of
121
- this License, whose permissions for other licensees extend to the
122
- entire whole, and thus to each and every part regardless of who wrote it.
123
-
124
- Thus, it is not the intent of this section to claim rights or contest
125
- your rights to work written entirely by you; rather, the intent is to
126
- exercise the right to control the distribution of derivative or
127
- collective works based on the Program.
128
-
129
- In addition, mere aggregation of another work not based on the Program
130
- with the Program (or with a work based on the Program) on a volume of
131
- a storage or distribution medium does not bring the other work under
132
- the scope of this License.
133
-
134
- 3. You may copy and distribute the Program (or a work based on it,
135
- under Section 2) in object code or executable form under the terms of
136
- Sections 1 and 2 above provided that you also do one of the following:
137
-
138
- a) Accompany it with the complete corresponding machine-readable
139
- source code, which must be distributed under the terms of Sections
140
- 1 and 2 above on a medium customarily used for software interchange; or,
141
-
142
- b) Accompany it with a written offer, valid for at least three
143
- years, to give any third party, for a charge no more than your
144
- cost of physically performing source distribution, a complete
145
- machine-readable copy of the corresponding source code, to be
146
- distributed under the terms of Sections 1 and 2 above on a medium
147
- customarily used for software interchange; or,
148
-
149
- c) Accompany it with the information you received as to the offer
150
- to distribute corresponding source code. (This alternative is
151
- allowed only for noncommercial distribution and only if you
152
- received the program in object code or executable form with such
153
- an offer, in accord with Subsection b above.)
154
-
155
- The source code for a work means the preferred form of the work for
156
- making modifications to it. For an executable work, complete source
157
- code means all the source code for all modules it contains, plus any
158
- associated interface definition files, plus the scripts used to
159
- control compilation and installation of the executable. However, as a
160
- special exception, the source code distributed need not include
161
- anything that is normally distributed (in either source or binary
162
- form) with the major components (compiler, kernel, and so on) of the
163
- operating system on which the executable runs, unless that component
164
- itself accompanies the executable.
165
-
166
- If distribution of executable or object code is made by offering
167
- access to copy from a designated place, then offering equivalent
168
- access to copy the source code from the same place counts as
169
- distribution of the source code, even though third parties are not
170
- compelled to copy the source along with the object code.
171
-
172
- 4. You may not copy, modify, sublicense, or distribute the Program
173
- except as expressly provided under this License. Any attempt
174
- otherwise to copy, modify, sublicense or distribute the Program is
175
- void, and will automatically terminate your rights under this License.
176
- However, parties who have received copies, or rights, from you under
177
- this License will not have their licenses terminated so long as such
178
- parties remain in full compliance.
179
-
180
- 5. You are not required to accept this License, since you have not
181
- signed it. However, nothing else grants you permission to modify or
182
- distribute the Program or its derivative works. These actions are
183
- prohibited by law if you do not accept this License. Therefore, by
184
- modifying or distributing the Program (or any work based on the
185
- Program), you indicate your acceptance of this License to do so, and
186
- all its terms and conditions for copying, distributing or modifying
187
- the Program or works based on it.
188
-
189
- 6. Each time you redistribute the Program (or any work based on the
190
- Program), the recipient automatically receives a license from the
191
- original licensor to copy, distribute or modify the Program subject to
192
- these terms and conditions. You may not impose any further
193
- restrictions on the recipients' exercise of the rights granted herein.
194
- You are not responsible for enforcing compliance by third parties to
195
- this License.
196
-
197
- 7. If, as a consequence of a court judgment or allegation of patent
198
- infringement or for any other reason (not limited to patent issues),
199
- conditions are imposed on you (whether by court order, agreement or
200
- otherwise) that contradict the conditions of this License, they do not
201
- excuse you from the conditions of this License. If you cannot
202
- distribute so as to satisfy simultaneously your obligations under this
203
- License and any other pertinent obligations, then as a consequence you
204
- may not distribute the Program at all. For example, if a patent
205
- license would not permit royalty-free redistribution of the Program by
206
- all those who receive copies directly or indirectly through you, then
207
- the only way you could satisfy both it and this License would be to
208
- refrain entirely from distribution of the Program.
209
-
210
- If any portion of this section is held invalid or unenforceable under
211
- any particular circumstance, the balance of the section is intended to
212
- apply and the section as a whole is intended to apply in other
213
- circumstances.
214
-
215
- It is not the purpose of this section to induce you to infringe any
216
- patents or other property right claims or to contest validity of any
217
- such claims; this section has the sole purpose of protecting the
218
- integrity of the free software distribution system, which is
219
- implemented by public license practices. Many people have made
220
- generous contributions to the wide range of software distributed
221
- through that system in reliance on consistent application of that
222
- system; it is up to the author/donor to decide if he or she is willing
223
- to distribute software through any other system and a licensee cannot
224
- impose that choice.
225
-
226
- This section is intended to make thoroughly clear what is believed to
227
- be a consequence of the rest of this License.
228
-
229
- 8. If the distribution and/or use of the Program is restricted in
230
- certain countries either by patents or by copyrighted interfaces, the
231
- original copyright holder who places the Program under this License
232
- may add an explicit geographical distribution limitation excluding
233
- those countries, so that distribution is permitted only in or among
234
- countries not thus excluded. In such case, this License incorporates
235
- the limitation as if written in the body of this License.
236
-
237
- 9. The Free Software Foundation may publish revised and/or new versions
238
- of the General Public License from time to time. Such new versions will
239
- be similar in spirit to the present version, but may differ in detail to
240
- address new problems or concerns.
241
-
242
- Each version is given a distinguishing version number. If the Program
243
- specifies a version number of this License which applies to it and "any
244
- later version", you have the option of following the terms and conditions
245
- either of that version or of any later version published by the Free
246
- Software Foundation. If the Program does not specify a version number of
247
- this License, you may choose any version ever published by the Free Software
248
- Foundation.
249
-
250
- 10. If you wish to incorporate parts of the Program into other free
251
- programs whose distribution conditions are different, write to the author
252
- to ask for permission. For software which is copyrighted by the Free
253
- Software Foundation, write to the Free Software Foundation; we sometimes
254
- make exceptions for this. Our decision will be guided by the two goals
255
- of preserving the free status of all derivatives of our free software and
256
- of promoting the sharing and reuse of software generally.
257
-
258
- NO WARRANTY
259
-
260
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
- FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
- OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
- PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
- OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
- TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
- PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
- REPAIR OR CORRECTION.
269
-
270
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
- REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
- INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
- OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
- TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
- YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
- PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
- POSSIBILITY OF SUCH DAMAGES.
279
-
280
- END OF TERMS AND CONDITIONS
281
-
282
- How to Apply These Terms to Your New Programs
283
-
284
- If you develop a new program, and you want it to be of the greatest
285
- possible use to the public, the best way to achieve this is to make it
286
- free software which everyone can redistribute and change under these terms.
287
-
288
- To do so, attach the following notices to the program. It is safest
289
- to attach them to the start of each source file to most effectively
290
- convey the exclusion of warranty; and each file should have at least
291
- the "copyright" line and a pointer to where the full notice is found.
292
-
293
- <one line to give the program's name and a brief idea of what it does.>
294
- Copyright (C) <year> <name of author>
295
-
296
- This program is free software; you can redistribute it and/or modify
297
- it under the terms of the GNU General Public License as published by
298
- the Free Software Foundation; either version 2 of the License, or
299
- (at your option) any later version.
300
-
301
- This program is distributed in the hope that it will be useful,
302
- but WITHOUT ANY WARRANTY; without even the implied warranty of
303
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
- GNU General Public License for more details.
305
-
306
- You should have received a copy of the GNU General Public License
307
- along with this program; if not, write to the Free Software
308
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
309
-
310
-
311
- Also add information on how to contact you by electronic and paper mail.
312
-
313
- If the program is interactive, make it output a short notice like this
314
- when it starts in an interactive mode:
315
-
316
- Gnomovision version 69, Copyright (C) year name of author
317
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318
- This is free software, and you are welcome to redistribute it
319
- under certain conditions; type `show c' for details.
320
-
321
- The hypothetical commands `show w' and `show c' should show the appropriate
322
- parts of the General Public License. Of course, the commands you use may
323
- be called something other than `show w' and `show c'; they could even be
324
- mouse-clicks or menu items--whatever suits your program.
325
-
326
- You should also get your employer (if you work as a programmer) or your
327
- school, if any, to sign a "copyright disclaimer" for the program, if
328
- necessary. Here is a sample; alter the names:
329
-
330
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
332
-
333
- <signature of Ty Coon>, 1 April 1989
334
- Ty Coon, President of Vice
335
-
336
- This General Public License does not permit incorporating your program into
337
- proprietary programs. If your program is a subroutine library, you may
338
- consider it more useful to permit linking proprietary applications with the
339
- library. If this is what you want to do, use the GNU Library General
340
- Public License instead of this License.
54
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
+ PURPOSE.
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ 2011-06-09 rocky <rockyb@rubyforge.org>
2
+
3
+ * ChangeLog, NEWS, Rakefile: Get ready for new release.
4
+
1
5
  2011-04-27 r <rocky@gnu.org>
2
6
 
3
7
  * README.md: Fix code example.
data/NEWS CHANGED
@@ -1,3 +1,11 @@
1
+ 0.3.4 July 4, 2011
2
+
3
+ - Change to Ruby License
4
+ - Add option 'term_adjust' to ignore terminal sequences in text
5
+ - Add :ljust => :auto to decide whether or not to automatically
6
+ left or right justify. When passing a hash parameter, the default
7
+ is :auto.
8
+
1
9
  0.3.3 June 12, 2011 Fleetwood release
2
10
 
3
11
  - More general but simpler inteface using an options
@@ -33,5 +41,3 @@
33
41
 
34
42
  - Initial release of Columnize, a module to print an Array in
35
43
  column-sorted order
36
-
37
- $Id$
data/README ADDED
@@ -0,0 +1,78 @@
1
+ = Columnize - Module to show an Array formatted as a String aligned in columns.
2
+
3
+ == Summary
4
+
5
+ In showing a long lists, sometimes one would prefer to see the value
6
+ arranged aligned in columns. Some examples include listing methods of
7
+ an object, listing debugger commands, or showing a numeric array with data
8
+ aligned.
9
+
10
+ === Setup
11
+
12
+ $ irb
13
+ >> a = (1..10).to_a
14
+ => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
15
+ >> require 'columnize'
16
+ => true
17
+ >> include Columnize
18
+ => Object
19
+ >> g = %w(bibrons golden madascar leopard mourning suras tokay)
20
+ => ["bibrons", "golden", "madascar", "leopard", "mourning", "suras", "tokay"]
21
+
22
+ === With numeric data
23
+
24
+ columnize(a)
25
+ => "1 2 3 4 5 6 7 8 9 10\n"
26
+ >> puts Columnize::columnize(a, :arrange_array => true, :displaywidth => 10)
27
+ [1, 2
28
+ 3, 4
29
+ 5, 6
30
+ 7, 8
31
+ 9, 10
32
+ ]
33
+ => nil
34
+ >> puts Columnize::columnize(a, :arrange_array => true, :displaywidth => 20)
35
+ [1, 2, 3, 4, 5, 6
36
+ 7, 8, 9, 10
37
+ ]
38
+
39
+ === With String data
40
+
41
+ >> puts columnize g, :displaywidth => 15
42
+ bibrons suras
43
+ golden tokay
44
+ madascar
45
+ leopard
46
+ mourning
47
+ => nil
48
+
49
+ >> puts columnize g, {:displaywidth => 18, :colsep => ' | '}
50
+ bibrons | suras
51
+ golden | tokay
52
+ madascar
53
+ leopard
54
+ mourning
55
+ => nil
56
+
57
+ >> puts columnize g, {:displaywidth => 18, :colsep => ' | ', :ljust=>false}
58
+ bibrons | suras
59
+ golden | tokay
60
+ madascar
61
+ leopard
62
+
63
+ == Credits
64
+
65
+ This is adapted from a method of the same name from Python's cmd module.
66
+
67
+ == Other stuff
68
+
69
+ Author:: Rocky Bernstein <rockyb@rubyforge.net>
70
+ License:: Copyright (c) 2007, 2011 Rocky Bernstein
71
+ Released under the GNU GPL 2 license
72
+
73
+ == Warranty
74
+
75
+ This program is distributed in the hope that it will be useful,
76
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
77
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78
+ GNU General Public License for more details.
data/Rakefile CHANGED
@@ -10,14 +10,15 @@ ROOT_DIR = File.dirname(__FILE__)
10
10
  require File.join(ROOT_DIR, '/lib/version')
11
11
 
12
12
  def gemspec
13
- @gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
13
+ @gemspec ||= eval(File.read('columnize.gemspec'),
14
+ binding, 'columnize.gemspec')
14
15
  end
15
16
 
16
17
  desc "Build the gem"
17
18
  task :package=>:gem
18
19
  task :gem=>:gemspec do
19
20
  Dir.chdir(ROOT_DIR) do
20
- sh "gem build .gemspec"
21
+ sh "gem build columnize.gemspec"
21
22
  FileUtils.mkdir_p 'pkg'
22
23
  FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
23
24
  end
@@ -0,0 +1,51 @@
1
+ # -*- Ruby -*-
2
+ # -*- encoding: utf-8 -*-
3
+ require 'rake'
4
+ require 'rubygems' unless
5
+ Object.const_defined?(:Gem)
6
+ require File.dirname(__FILE__) + "/lib/version" unless
7
+ Object.const_defined?(:'Columnize')
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.authors = ['R. Bernstein']
11
+ spec.date = Time.now
12
+ spec.description = '
13
+ In showing a long lists, sometimes one would prefer to see the value
14
+ arranged aligned in columns. Some examples include listing methods
15
+ of an object or debugger commands.
16
+
17
+ An Example:
18
+ ```
19
+ require "columnize"
20
+ Columnize.columnize((1..100).to_a, :displaywidth=>60)
21
+ puts Columnize.columnize((1..100).to_a, :displaywidth=>60)
22
+ 1 8 15 22 29 36 43 50 57 64 71 78 85 92 99
23
+ 2 9 16 23 30 37 44 51 58 65 72 79 86 93 100
24
+ 3 10 17 24 31 38 45 52 59 66 73 80 87 94
25
+ 4 11 18 25 32 39 46 53 60 67 74 81 88 95
26
+ 5 12 19 26 33 40 47 54 61 68 75 82 89 96
27
+ 6 13 20 27 34 41 48 55 62 69 76 83 90 97
28
+ 7 14 21 28 35 42 49 56 63 70 77 84 91 98
29
+
30
+ See Examples in the rdoc documentation for more examples.
31
+ ```
32
+ '
33
+ spec.email = 'rockyb@rubyforge.net'
34
+ spec.files = `git ls-files`.split("\n")
35
+ spec.homepage = 'https://github.com/rocky/columnize'
36
+ spec.name = 'columnize'
37
+ spec.licenses = ['Ruby', 'GPL2']
38
+ spec.platform = Gem::Platform::RUBY
39
+ spec.require_path = 'lib'
40
+ spec.required_ruby_version = '>= 1.8.2'
41
+ spec.rubyforge_project = 'columnize'
42
+ spec.summary = 'Module to format an Array as an Array of String aligned in columns'
43
+ spec.version = Columnize::VERSION
44
+ spec.has_rdoc = true
45
+ spec.extra_rdoc_files = %w(README lib/columnize.rb COPYING)
46
+
47
+ # Make the readme file the start page for the generated html
48
+ spec.rdoc_options += %w(--verbose --main README)
49
+ spec.rdoc_options += ['--title', "Columnize #{Columnize::VERSION} Documentation"]
50
+
51
+ end
@@ -1,28 +1,8 @@
1
- # Copyright (C) 2007, 2008, 2009, 2010, 2011 Rocky Bernstein
2
- # <rockyb@rubyforge.net>
3
- #
4
- # This program is free software; you can redistribute it and/or modify
5
- # it under the terms of the GNU General Public License as published by
6
- # the Free Software Foundation; either version 2 of the License, or
7
- # (at your option) any later version.
8
- #
9
- # This program is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU General Public License
15
- # along with this program; if not, write to the Free Software
16
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
- # 02110-1301 USA.
18
- #
19
-
20
- # Author:: Rocky Bernstein (mailto:rockyb@rubyforge.net)
21
- #
22
- # = Columnize
23
1
  # Module to format an Array as an Array of String aligned in columns.
24
2
  #
25
- # == SYNOPSIS
3
+ # :main:README.md
4
+ #
5
+ # == Summary
26
6
  # Display a list of strings as a compact set of columns.
27
7
  #
28
8
  # For example, for a line width of 4 characters (arranged vertically):
@@ -32,30 +12,73 @@
32
12
  # ['1', '2,', '3', '4'] => '1 2\n3 4\n'
33
13
  #
34
14
  # Each column is only as wide as necessary. By default, columns are
35
- # separated by two spaces (one was not legible enough).
36
-
37
-
38
- # Adapted from
39
- # the routine of the same name in cmd.py
15
+ # separated by two spaces. Options are avalable for setting
16
+ # * the display width
17
+ # * the column separator
18
+ # * the line prefix
19
+ # * whether to ignore terminal codes in text size calculation
20
+ # * whether to left justify text instead of right justify
21
+ #
22
+ # == License
23
+ #
24
+ # Columnize is copyright (C) 2007, 2008, 2009, 2010, 2011 Rocky Bernstein
25
+ # <rockyb@rubyforge.net>
26
+ #
27
+ # All rights reserved. You can redistribute and/or modify it under
28
+ # the same terms as Ruby.
29
+ #
30
+ # Adapted from the routine of the same name in Python +cmd.py+.
40
31
 
41
32
  module Columnize
42
33
 
34
+ # When an option is not specified for the below keys, these
35
+ # are the defaults.
43
36
  DEFAULT_OPTS = {
44
- :displaywidth => 80,
37
+ :arrange_array => false,
38
+ :arrange_vertical => true,
39
+ :array_prefix => false,
40
+ :array_suffix => '',
45
41
  :colsep => ' ',
46
- :ljust => true,
42
+ :displaywidth => 80,
47
43
  :lineprefix => '',
48
- :arrange_vertical => true
44
+ :ljust => :auto,
45
+ :term_adjust => false
49
46
  }
50
47
 
51
48
  module_function
49
+
50
+ # Options parsing routine for Columnize::columnize. In the preferred
51
+ # newer style, +args+ is either a hash where each key is one of the option
52
+ # names:
53
+ #
54
+ # [arrange_vertical] Arrange list vertically rather than horizontally. This is the default
55
+ # [colsep] String used to separate columns
56
+ # [displaywidth] Maximum width of each line
57
+ # [ljust] Boolean or +:auto+: Left-justify fields in a column? The default is +true+. If
58
+ # the :auto, then right-justify if every element of the data is a kind of Numeric.
59
+ # [lineprefix] String: string to prepend to each line. The default is ''.
60
+ #
61
+ # In the older style positional arguments are used and the positions
62
+ # are in the order: +displaywidth+, +colsep+, +arrange_vertical+,
63
+ # +ljust+, and +lineprefix+.
52
64
  def parse_columnize_options(args)
53
65
  list = args.shift
54
66
  if 1 == args.size && args[0].kind_of?(Hash)
55
- return list, DEFAULT_OPTS.merge(args[0])
67
+ opts = DEFAULT_OPTS.merge(args[0])
68
+ if opts[:arrange_array]
69
+ opts[:array_prefix] = '['
70
+ opts[:lineprefix] = ' '
71
+ opts[:array_suffix] = "]\n"
72
+ opts[:colsep] = ', '
73
+ opts[:arrange_vertical] = false
74
+ end
75
+ opts[:ljust] = !(list.all?{|datum| datum.kind_of?(Numeric)}) if
76
+ opts[:ljust] == :auto
77
+ return list, opts
56
78
  else
57
79
  opts = DEFAULT_OPTS.dup
58
- %w(displaywidth colsep arrange_vertical ljust lineprefix).each do |field|
80
+ %w(displaywidth colsep arrange_vertical ljust lineprefix
81
+ ).each do |field|
59
82
  break if args.empty?
60
83
  opts[field.to_sym] = args.shift
61
84
  end
@@ -63,6 +86,16 @@ module Columnize
63
86
  end
64
87
  end
65
88
 
89
+ # Return the length of String +cell+. If Boolean +term_adjust+ is true,
90
+ # ignore terminal sequences in +cell+.
91
+ def cell_size(cell, term_adjust)
92
+ if term_adjust
93
+ cell.gsub(/\e\[.*?m/, '')
94
+ else
95
+ cell
96
+ end.size
97
+ end
98
+
66
99
  # Return a list of strings with embedded newlines (\n) as a compact
67
100
  # set of columns arranged horizontally or vertically.
68
101
  #
@@ -96,7 +129,8 @@ module Columnize
96
129
 
97
130
  nrows = ncols = 0 # Make nrows, ncols have more global scope
98
131
  colwidths = [] # Same for colwidths
99
- opts[:displaywidth] = [4, opts[:displaywidth] - opts[:lineprefix].length].max
132
+ opts[:displaywidth] = [4,
133
+ opts[:displaywidth] - opts[:lineprefix].length].max
100
134
  if opts[:arrange_vertical]
101
135
  array_index = lambda {|num_rows, row, col| num_rows*col + row }
102
136
  # Try every row count from 1 upwards
@@ -116,7 +150,7 @@ module Columnize
116
150
  if i >= l.size
117
151
  break
118
152
  end
119
- colwidth = [colwidth, l[i].size].max
153
+ colwidth = [colwidth, cell_size(l[i], opts[:term_adjust])].max
120
154
  end
121
155
  colwidths << colwidth
122
156
  totwidth += colwidth + opts[:colsep].length
@@ -141,7 +175,7 @@ module Columnize
141
175
  col = _col
142
176
  i = array_index.call(nrows, row, col)
143
177
  if i >= l.size
144
- x = ""
178
+ x = ''
145
179
  else
146
180
  x = l[i]
147
181
  end
@@ -187,7 +221,7 @@ module Columnize
187
221
  if i >= rounded_size
188
222
  break
189
223
  elsif i < l.size
190
- colwidth = [colwidth, l[i].size].max
224
+ colwidth = [colwidth, cell_size(l[i], opts[:term_adjust])].max
191
225
  end
192
226
  end
193
227
  colwidths << colwidth
@@ -214,6 +248,7 @@ module Columnize
214
248
  # Now we just have to format each of the
215
249
  # rows.
216
250
  s = ''
251
+ prefix = opts[:array_prefix] || opts[:lineprefix]
217
252
  1.upto(nrows) do |row|
218
253
  texts = []
219
254
  0.upto(ncols-1) do |col|
@@ -232,8 +267,10 @@ module Columnize
232
267
  texts[col] = texts[col].rjust(colwidths[col])
233
268
  end
234
269
  end
235
- s += "%s%s\n" % [opts[:lineprefix], texts.join(opts[:colsep])]
270
+ s += "%s%s\n" % [prefix, texts.join(opts[:colsep])]
271
+ prefix = opts[:lineprefix]
236
272
  end
273
+ s += opts[:array_suffix]
237
274
  return s
238
275
  end
239
276
  end
@@ -1,3 +1,7 @@
1
+ # Sets constant Columnize::VERSION, the version number of
2
+ # this package. It is used in Gem creation but can also be consulted after
3
+ # require'ing 'columnize'.
1
4
  module Columnize
2
- VERSION = '0.3.3'
5
+ # The current version of this package
6
+ VERSION = '0.3.4'
3
7
  end
@@ -8,6 +8,13 @@ class TestColumnize < Test::Unit::TestCase
8
8
  require File.join(@@TOP_SRC_DIR, 'columnize.rb')
9
9
  include Columnize
10
10
 
11
+ def test_cell_size
12
+ assert_equal(3, cell_size('abc', false))
13
+ assert_equal(3, cell_size('abc', true))
14
+ assert_equal(6, cell_size("\e[0;31mObject\e[0;4m", true))
15
+ assert_equal(19, cell_size("\e[0;31mObject\e[0;4m", false))
16
+ end
17
+
11
18
  # test columnize
12
19
  def test_basic
13
20
  # Try at least one test where we give the module name explicitely.
@@ -17,10 +17,64 @@ class TestHashFormat < Test::Unit::TestCase
17
17
  assert_equal 70, opts[:displaywidth]
18
18
  assert_equal '|', opts[:colsep]
19
19
  end
20
-
21
- def basic
22
- opts = {:xxx => 10, :yyy => ', '}
20
+
21
+ def test_parse_columnize_ljust
22
+ list, opts = parse_columnize_options([[1.5, 2, 3], {:ljust => :auto}])
23
+ assert_equal false, opts[:ljust]
24
+ list, opts = parse_columnize_options([[1.5, 2, 3], {:ljust => false}])
25
+ assert_equal false, opts[:ljust]
26
+ list, opts = parse_columnize_options([[1.5, 2, 3], {:ljust => true}])
27
+ assert_equal true, opts[:ljust]
28
+ list, opts = parse_columnize_options([[1, 2, 'b'], {:ljust => :auto}])
29
+ assert_equal true, opts[:ljust]
30
+ end
31
+
32
+ def test_new_hash
33
+ list, opts = parse_columnize_options([[], {:displaywidth => 40,
34
+ :colsep => ', ',
35
+ :term_adjust => true,
36
+ }])
37
+ [[:displaywidth, 40], [:colsep, ', '], [:term_adjust, true]].each do
38
+ |field, value|
39
+ assert_equal(value , opts[field])
40
+ end
41
+ list, opts = parse_columnize_options([[], {:displaywidth => 40,
42
+ :colsep => ', ',
43
+ }])
44
+ assert_equal(false , opts[:term_adjust])
45
+ opts = {:colsep => ', '}
23
46
  assert_equal("1, 2, 3\n",
24
47
  Columnize::columnize([1, 2, 3], opts))
25
48
  end
49
+
50
+ def test_array
51
+ data = (0..54).to_a
52
+ assert_equal(
53
+ "[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9\n" +
54
+ " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19\n" +
55
+ " 20, 21, 22, 23, 24, 25, 26, 27, 28, 29\n" +
56
+ " 30, 31, 32, 33, 34, 35, 36, 37, 38, 39\n" +
57
+ " 40, 41, 42, 43, 44, 45, 46, 47, 48, 49\n" +
58
+ " 50, 51, 52, 53, 54\n" +
59
+ "]\n",
60
+ columnize(data,
61
+ :arrange_array => true, :ljust => false,
62
+ :displaywidth => 39))
63
+ end
64
+
65
+ def test_justify
66
+ data = (0..54).to_a
67
+ assert_equal(
68
+ "[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9\n" +
69
+ " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19\n" +
70
+ " 20, 21, 22, 23, 24, 25, 26, 27, 28, 29\n" +
71
+ " 30, 31, 32, 33, 34, 35, 36, 37, 38, 39\n" +
72
+ " 40, 41, 42, 43, 44, 45, 46, 47, 48, 49\n" +
73
+ " 50, 51, 52, 53, 54\n" +
74
+ "]\n",
75
+ columnize(data,
76
+ :arrange_array => true,
77
+ :displaywidth => 39))
78
+ end
79
+
26
80
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: columnize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 4
9
+ version: 0.3.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - R. Bernstein
@@ -9,78 +14,78 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2011-06-11 00:00:00 -04:00
17
+ date: 2011-07-05 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
16
- description: |
17
-
18
- In showing a long lists, sometimes one would prefer to see the value
19
- arranged aligned in columns. Some examples include listing methods
20
- of an object or debugger commands.
21
-
22
- An Example:
23
- require "columnize"
24
- print columnize((1..100).to_a.map{|x| "%2d" % x}, 60)
25
-
26
- 1 8 15 22 29 36 43 50 57 64 71 78 85 92 99
27
- 2 9 16 23 30 37 44 51 58 65 72 79 86 93 100
28
- 3 10 17 24 31 38 45 52 59 66 73 80 87 94
29
- 4 11 18 25 32 39 46 53 60 67 74 81 88 95
30
- 5 12 19 26 33 40 47 54 61 68 75 82 89 96
31
- 6 13 20 27 34 41 48 55 62 69 76 83 90 97
32
- 7 14 21 28 35 42 49 56 63 70 77 84 91 98
33
-
21
+ description: "\n\
22
+ In showing a long lists, sometimes one would prefer to see the value\n\
23
+ arranged aligned in columns. Some examples include listing methods\n\
24
+ of an object or debugger commands. \n\n\
25
+ An Example:\n\
26
+ ```\n\
27
+ require \"columnize\"\n Columnize.columnize((1..100).to_a, :displaywidth=>60)\n puts Columnize.columnize((1..100).to_a, :displaywidth=>60)\n 1 8 15 22 29 36 43 50 57 64 71 78 85 92 99\n 2 9 16 23 30 37 44 51 58 65 72 79 86 93 100\n 3 10 17 24 31 38 45 52 59 66 73 80 87 94\n 4 11 18 25 32 39 46 53 60 67 74 81 88 95\n 5 12 19 26 33 40 47 54 61 68 75 82 89 96\n 6 13 20 27 34 41 48 55 62 69 76 83 90 97\n 7 14 21 28 35 42 49 56 63 70 77 84 91 98\n\n See Examples in the rdoc documentation for more examples.\n\
28
+ ```\n"
34
29
  email: rockyb@rubyforge.net
35
30
  executables: []
36
31
 
37
32
  extensions: []
38
33
 
39
34
  extra_rdoc_files:
40
- - README.md
35
+ - README
41
36
  - lib/columnize.rb
42
37
  - COPYING
43
38
  files:
39
+ - .gitignore
44
40
  - AUTHORS
45
41
  - COPYING
46
42
  - ChangeLog
47
43
  - Makefile
48
44
  - NEWS
49
- - README.md
45
+ - README
50
46
  - Rakefile
47
+ - columnize.gemspec
48
+ - lib/Makefile
51
49
  - lib/columnize.rb
52
50
  - lib/version.rb
53
- - lib/Makefile
54
51
  - test/test-columnize.rb
55
52
  - test/test-hashparm.rb
56
53
  has_rdoc: true
57
- homepage: http://rubyforge.org/projects/rocky-hacks/columnize
54
+ homepage: https://github.com/rocky/columnize
58
55
  licenses:
56
+ - Ruby
59
57
  - GPL2
60
58
  post_install_message:
61
59
  rdoc_options:
60
+ - --verbose
62
61
  - --main
63
- - README.md
62
+ - README
64
63
  - --title
65
- - Columnize 0.3.3 Documentation
64
+ - Columnize 0.3.4 Documentation
66
65
  require_paths:
67
66
  - lib
68
67
  required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
69
  requirements:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
+ segments:
73
+ - 1
74
+ - 8
75
+ - 2
72
76
  version: 1.8.2
73
- version:
74
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
75
79
  requirements:
76
80
  - - ">="
77
81
  - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
78
84
  version: "0"
79
- version:
80
85
  requirements: []
81
86
 
82
87
  rubyforge_project: columnize
83
- rubygems_version: 1.3.5
88
+ rubygems_version: 1.3.7
84
89
  signing_key:
85
90
  specification_version: 3
86
91
  summary: Module to format an Array as an Array of String aligned in columns
data/README.md DELETED
@@ -1,40 +0,0 @@
1
- # Columnize - Module to show an Array formatted as a String aligned in columns.
2
-
3
- ## Summary
4
-
5
- In showing a long lists, sometimes one would prefer to see the value
6
- arranged aligned in columns. Some examples include listing methods
7
- of an object or debugger commands.
8
-
9
- ```
10
- require 'columnize'
11
- columnize([1, 2, 3])
12
- 1 2 3
13
- a = (1..100).to_a
14
- print columnize((1..100).to_a.map{|x| "%2d" % x}, 60)
15
-
16
- 1 8 15 22 29 36 43 50 57 64 71 78 85 92 99
17
- 2 9 16 23 30 37 44 51 58 65 72 79 86 93 100
18
- 3 10 17 24 31 38 45 52 59 66 73 80 87 94
19
- 4 11 18 25 32 39 46 53 60 67 74 81 88 95
20
- 5 12 19 26 33 40 47 54 61 68 75 82 89 96
21
- 6 13 20 27 34 41 48 55 62 69 76 83 90 97
22
- 7 14 21 28 35 42 49 56 63 70 77 84 91 98
23
- ```
24
-
25
- ## Credits
26
-
27
- This is adapted from a method of the same name from Python's cmd module.
28
-
29
- ## Other stuff
30
-
31
- Author:: Rocky Bernstein <rockyb@rubyforge.net>
32
- License:: Copyright (c) 2007, 2011 Rocky Bernstein
33
- Released under the GNU GPL 2 license
34
-
35
- ## Warranty
36
-
37
- This program is distributed in the hope that it will be useful,
38
- but WITHOUT ANY WARRANTY; without even the implied warranty of
39
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40
- GNU General Public License for more details.