columnizer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ module Columnizer
2
+
3
+ def self.columnize_print(data, options = {})
4
+ puts self.columnize(data, options)
5
+ end
6
+
7
+ def self.columnize(data, options = {})
8
+ # get sizes
9
+ sizes = field_sizes(data)
10
+ # now go through and print them
11
+ str = ''
12
+ data.each do |row|
13
+ row.each_with_index do |field, index|
14
+ str += field + ' ' * (sizes[index] - field.size + (index == sizes.size - 1 ? 0 : options[:padding] || 0))
15
+ end
16
+ for index in row.size...sizes.size do # pad out
17
+ str += ' ' * sizes[index]
18
+ end
19
+ str += "\n"
20
+ end
21
+ str
22
+ end
23
+
24
+ private
25
+
26
+ # get all of the sizes
27
+ def self.field_sizes(data)
28
+ sizes = []
29
+ data.each do |row|
30
+ row.each_with_index do |field, index|
31
+ c = sizes[index]
32
+ sizes[index] = field.size if c.nil? || c < field.size
33
+ end
34
+ end
35
+ sizes
36
+ end
37
+
38
+ end
@@ -0,0 +1,11 @@
1
+ module Columnizer
2
+
3
+ def self.version
4
+ VERSION.join('.')
5
+ end
6
+
7
+ private
8
+
9
+ VERSION = [0, 0, 1]
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: columnizer
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - John Crepezzi
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-04 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Put multi-dimensional arrays into neat columns
23
+ email: john.crepezzi@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/columnizer/version.rb
32
+ - lib/columnizer.rb
33
+ has_rdoc: true
34
+ homepage: http://github.com/seejohnrun/columnizer
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project: columnizer
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Neat columns
67
+ test_files: []
68
+