table-formatter 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/table-formatter.rb +19 -9
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f189f28298623d39cbc5dfe7472e6e1b0004d74a
|
4
|
+
data.tar.gz: d1b8388ef949406c43c754c3f28ece615927f0b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d9bdb0fa2d4bc236616f71dd5c773b43a375d83d0eaa890ec3df8a74539325205b7cb3ff565f5be2c4ebd0c308626cdc9bd396650679bea2471da820f8714d9
|
7
|
+
data.tar.gz: 7542f4ed68995942f3b16501dc88b696fbcea78551c51ad22982175acbd28eab0611ddd8e3d602b63301d2e8aea70b42fff0ae2eb31de5ebb0f32edacfd97038
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/table-formatter.rb
CHANGED
@@ -4,15 +4,17 @@
|
|
4
4
|
|
5
5
|
class TableFormatter
|
6
6
|
|
7
|
-
attr_accessor :source, :labels, :border
|
7
|
+
attr_accessor :source, :labels, :border, :divider
|
8
8
|
|
9
9
|
def initialize(opt={})
|
10
10
|
|
11
|
-
o = {source: nil, labels: nil, border: true}.merge(opt)
|
11
|
+
o = {source: nil, labels: nil, border: true, nowrap: false}.merge(opt)
|
12
12
|
super()
|
13
13
|
@source = o[:source]
|
14
|
-
@raw_labels = o[:labels]
|
14
|
+
@raw_labels = o[:labels] if o[:labels]
|
15
15
|
@border = o[:border]
|
16
|
+
@nowrap = o[:nowrap]
|
17
|
+
@divider = o[:divider] if o[:divider]
|
16
18
|
@maxwidth = 60
|
17
19
|
end
|
18
20
|
|
@@ -36,14 +38,16 @@ class TableFormatter
|
|
36
38
|
@maxwidth = width if width
|
37
39
|
a = @source.map {|x| x.map.to_a}.to_a
|
38
40
|
labels = @labels
|
41
|
+
|
39
42
|
column_widths = fetch_column_widths(a)
|
40
43
|
|
41
44
|
column_widths[-1] -= column_widths.inject(&:+) - width if width
|
42
45
|
|
43
46
|
records = format_rows(a, column_widths)
|
44
47
|
|
45
|
-
div = (border == true ? '-' : '
|
46
|
-
label_buffer = ''
|
48
|
+
div = (border == true ? '-' : '') * records[0].length + "\n"
|
49
|
+
label_buffer = ''
|
50
|
+
|
47
51
|
label_buffer = format_cols(labels, column_widths) + "\n" + div if labels
|
48
52
|
|
49
53
|
div + label_buffer + records.join("\n") + "\n" + div
|
@@ -67,11 +71,17 @@ class TableFormatter
|
|
67
71
|
end
|
68
72
|
|
69
73
|
def format_cols(row, col_widths)
|
70
|
-
bar =
|
71
|
-
|
74
|
+
bar = ''
|
75
|
+
bar = '|' if border == true
|
76
|
+
bar = divider if divider
|
77
|
+
|
78
|
+
buffer = divider ? '' : bar #unless divider
|
72
79
|
row.each_with_index do |col, i|
|
73
|
-
|
80
|
+
|
81
|
+
align = @align_cols ? @align_cols[i] : :ljust
|
82
|
+
buffer += col.method(align).call(col_widths[i] + 2) + bar
|
74
83
|
end
|
84
|
+
buffer.sub!(/#{bar}$/,'') if divider
|
75
85
|
buffer
|
76
86
|
end
|
77
87
|
|
@@ -82,7 +92,7 @@ class TableFormatter
|
|
82
92
|
col_widths[-1] -= col_widths.inject(&:+) - @maxwidth if @width > @maxwidth
|
83
93
|
|
84
94
|
a.each_with_index do |x,i|
|
85
|
-
col_rows = wrap(x[-1], col_widths[-1]).split(/\n/)
|
95
|
+
col_rows = @nowrap == false ? wrap(x[-1], col_widths[-1]).split(/\n/) : [x[-1]]
|
86
96
|
if col_rows.length > 1 then
|
87
97
|
x[-1] = col_rows[0]
|
88
98
|
col_rows[1..-1].map.with_index {|y,j| a.insert(i+1+j, Array.new(x.length - 1,'') + [y])}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
87MJlDPDYzp5yHAWkCW+L5wNO0Z0kdkibE/RZ9yGgZ7rSPRUUBqwsxNfwvyVh8Gl
|
30
30
|
Ld73E8JjE0JpECfuT5M6ch5PUBtf1txl
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2013-
|
32
|
+
date: 2013-10-24 00:00:00.000000000 Z
|
33
33
|
dependencies: []
|
34
34
|
description:
|
35
35
|
email: james@r0bertson.co.uk
|
metadata.gz.sig
CHANGED
Binary file
|