columnizer 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ddd7f767e3a511899bff40090a699d2c7e48714
4
+ data.tar.gz: 26e66ae77aa79cf4b30dd5ab461b0e5083621695
5
+ SHA512:
6
+ metadata.gz: 17958937e01d36eb59585ede9e931b2082c030a00f7e4de84306b91e079c14684458b02349530b7f010c9823317f76c5c27a866af506383ccc20dad047c9ed9c
7
+ data.tar.gz: 4e6bc1919899fe2e7594657482075d1fa731de5c4642b50021d58c10e4dba4133dd68c920507adbe0b788966348acd105fce447e97462a7b6a28f741b820b5e5
@@ -1,20 +1,20 @@
1
1
  module Columnizer
2
2
 
3
- def self.columnize_print(data, options = {})
4
- puts self.columnize(data, options)
3
+ extend self
4
+
5
+ def columnize_print(data, options = {})
6
+ puts columnize(data, options)
5
7
  end
6
8
 
7
- def self.columnize(data, options = {})
9
+ def columnize(data, options = {})
8
10
  # get sizes
9
11
  sizes = field_sizes(data)
12
+ padding = options[:padding] || 0
10
13
  # now go through and print them
11
14
  str = ''
12
15
  data.each do |row|
13
- row.each_with_index do |field, index|
14
- str += field.to_s + ' ' * (sizes[index] - field.to_s.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]
16
+ sizes.size.times do |i|
17
+ str += col_str(row[i], sizes[i], i == sizes.size - 1 ? 0 : padding)
18
18
  end
19
19
  str += "\n"
20
20
  end
@@ -23,14 +23,22 @@ module Columnizer
23
23
 
24
24
  private
25
25
 
26
+ # Get an individual column
27
+ def col_str(item, size, padding)
28
+ str = item.to_s
29
+ str += ' ' * (size - str.size)
30
+ str += ' ' * padding
31
+ str
32
+ end
33
+
26
34
  # get all of the sizes
27
- def self.field_sizes(data)
35
+ def field_sizes(data)
28
36
  sizes = []
29
37
  data.each do |row|
30
38
  row.each_with_index do |field, index|
31
39
  c = sizes[index]
32
40
  sizes[index] = field.to_s.size if c.nil? || c < field.to_s.size
33
- end
41
+ end
34
42
  end
35
43
  sizes
36
44
  end
@@ -6,6 +6,6 @@ module Columnizer
6
6
 
7
7
  private
8
8
 
9
- VERSION = [0, 0, 3]
9
+ VERSION = [0, 0, 4]
10
10
 
11
11
  end
metadata CHANGED
@@ -1,68 +1,44 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: columnizer
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - John Crepezzi
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-01-04 00:00:00 -05:00
19
- default_executable:
11
+ date: 2013-12-23 00:00:00.000000000 Z
20
12
  dependencies: []
21
-
22
13
  description: Put multi-dimensional arrays into neat columns
23
14
  email: john.crepezzi@gmail.com
24
15
  executables: []
25
-
26
16
  extensions: []
27
-
28
17
  extra_rdoc_files: []
29
-
30
- files:
18
+ files:
31
19
  - lib/columnizer/version.rb
32
20
  - lib/columnizer.rb
33
- has_rdoc: true
34
21
  homepage: http://github.com/seejohnrun/columnizer
35
22
  licenses: []
36
-
23
+ metadata: {}
37
24
  post_install_message:
38
25
  rdoc_options: []
39
-
40
- require_paths:
26
+ require_paths:
41
27
  - 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"
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
60
38
  requirements: []
61
-
62
39
  rubyforge_project: columnizer
63
- rubygems_version: 1.3.7
40
+ rubygems_version: 2.0.6
64
41
  signing_key:
65
- specification_version: 3
42
+ specification_version: 4
66
43
  summary: Neat columns
67
44
  test_files: []
68
-