table-formatter 0.4.4 → 0.4.5
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.
- 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: 3e6353a2265f8f3d4082fe28c9c5618ae040c4e6
|
4
|
+
data.tar.gz: a00e6ec5d1e56f1b0937303431251978593033c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c015e6389cc56148354d28b4140ba825f80902e697eca723a80740f7fd7e728a810d73accc10838ccd4dcaa361e1790098f33412c894e0b4241e6c8bcc810baf
|
7
|
+
data.tar.gz: 2866aa2a82955308d6f95d3be08a60a2d6a521c57e9eca1d834cd83ded88e5b37f53631fbbae9b2629d540aa5373df8d4a833c6aeabd8197bdd7561c049fcc9c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/table-formatter.rb
CHANGED
@@ -7,7 +7,7 @@ class TableFormatter
|
|
7
7
|
attr_accessor :source, :labels, :border, :divider, :markdown, :col_justify
|
8
8
|
|
9
9
|
def initialize(source: nil, labels: nil, border: true, wrap: true,
|
10
|
-
|
10
|
+
divider: nil, markdown: false, innermarkdown: false, debug: false)
|
11
11
|
|
12
12
|
super()
|
13
13
|
@source = source.map {|x| x.map(&:to_s)} if source
|
@@ -18,6 +18,7 @@ class TableFormatter
|
|
18
18
|
@maxwidth = 60
|
19
19
|
@markdown = markdown
|
20
20
|
@innermarkdown = innermarkdown
|
21
|
+
@debug = debug
|
21
22
|
|
22
23
|
end
|
23
24
|
|
@@ -94,13 +95,20 @@ class TableFormatter
|
|
94
95
|
print_row = -> (row, widths) do
|
95
96
|
'| ' + row.map\
|
96
97
|
.with_index {|y,i| y.to_s.ljust(widths[i])}.join(' | ') + " |\n"
|
97
|
-
end
|
98
|
+
end
|
98
99
|
|
99
100
|
print_thline = -> (row, widths) do
|
100
101
|
'|:' + row.map\
|
101
102
|
.with_index {|y,i| y.to_s.ljust(widths[i])}.join('|:') + "|\n"
|
102
103
|
end
|
103
|
-
|
104
|
+
|
105
|
+
if @debug then
|
106
|
+
|
107
|
+
puts '@labels: ' + @labels.inspect
|
108
|
+
puts 'thline: ' + print_thline.inspect
|
109
|
+
|
110
|
+
end
|
111
|
+
|
104
112
|
print_rows = -> (rows, widths) do
|
105
113
|
rows.map {|x| print_row.call(x,widths)}.join
|
106
114
|
end
|
@@ -147,15 +155,16 @@ class TableFormatter
|
|
147
155
|
vals).transpose.map{|x| x.max_by(&:length).length}
|
148
156
|
|
149
157
|
th = if @labels then
|
150
|
-
print_row.call(
|
158
|
+
print_row.call(fields, widths)
|
151
159
|
else
|
152
160
|
''
|
153
161
|
end
|
154
162
|
|
155
163
|
th_line = print_thline.call widths.map {|x| '-' * (x+1)}, widths
|
156
164
|
tb = print_rows.call(vals, widths)
|
157
|
-
|
158
|
-
|
165
|
+
th_line2 = justify(th_line, @col_justify)
|
166
|
+
|
167
|
+
table = th + th_line2 + tb
|
159
168
|
end
|
160
169
|
|
161
170
|
def display_markdown2(a, fields)
|
@@ -189,9 +198,10 @@ class TableFormatter
|
|
189
198
|
end
|
190
199
|
|
191
200
|
def fetch_column_widths(a)
|
192
|
-
|
201
|
+
|
202
|
+
puts 'a: ' + a.inspect if @debug
|
193
203
|
d = tabulate(a).map &:flatten
|
194
|
-
|
204
|
+
puts 'd: ' + d.inspect if @debug
|
195
205
|
# find the maximum lengths
|
196
206
|
d.map{|x| x.max_by(&:length).length}
|
197
207
|
|
@@ -272,4 +282,4 @@ class TableFormatter
|
|
272
282
|
a[0].zip(a.length > 2 ? tabulate(a[1..-1]) : a[-1])
|
273
283
|
end
|
274
284
|
|
275
|
-
end
|
285
|
+
end
|
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.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
HGsLe8SKG8DXaaZxtrfB5toes3L8kzgWrblCbrvE10LDGRcRXwMSshNtb9iyK1mh
|
32
32
|
pR4QFidc/b8Rlw==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2018-
|
34
|
+
date: 2018-02-18 00:00:00.000000000 Z
|
35
35
|
dependencies: []
|
36
36
|
description:
|
37
37
|
email: james@jamesrobertson.eu
|
metadata.gz.sig
CHANGED
Binary file
|