table-formatter 0.2.0 → 0.3.0
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 +1 -1
- data/lib/table-formatter.rb +35 -11
- metadata +20 -19
- 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: 56ff8ada05a246d2184ea4fed379eb0324a95719
|
4
|
+
data.tar.gz: 3ca9233356b47601cb4cf73a0f7d2c8e1f1f68ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b777176fc5f4b9f413caae17d92fda82f48d4037ce883917eeb7bf8fe95e7e6c5d9f061004f1b02bb7fafa027c4f8c6716b9f751e9f086addf6dc76b6aec352
|
7
|
+
data.tar.gz: 2399d85f2b8af41caf38c833031e18a8176476233c3f08444e3889f316ab280ab95b574b15f17e0371dfe755a57988b4c169db3b679832db221832282a8044bb
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
�����؍2n.�2����E~Ӊ��V��l?l57�g�I�$q���&��e^�_C�GP��%�@�Ԩ����y����:��fQ�M*��!���p@��F6�B��c<�y�f�����Xқ�S���Q�����QΙ�s�8������23�]��ĖW_u��m�̓*�&�F�}�}Nz)YI髰��3Ry�le|5��Ǫ]1Y�!����y���s�4:&c����R�Y����^�1a�&!!�eyM���SH�Ð�e���
|
data/lib/table-formatter.rb
CHANGED
@@ -10,24 +10,27 @@ class TableFormatter
|
|
10
10
|
|
11
11
|
super()
|
12
12
|
@source = source
|
13
|
-
@
|
13
|
+
@labels = labels
|
14
14
|
@border = border
|
15
15
|
@wrap = wrap
|
16
16
|
@divider = divider
|
17
17
|
@maxwidth = 60
|
18
|
+
|
18
19
|
end
|
19
20
|
|
20
|
-
def display(width=nil, widths: nil)
|
21
|
+
def display(width=nil, widths: nil, markdown: false)
|
22
|
+
|
23
|
+
return display_markdown(@source, @labels) if markdown
|
21
24
|
|
22
|
-
if @
|
25
|
+
if @labels then
|
23
26
|
|
24
|
-
@align_cols,
|
27
|
+
@align_cols, labels = [], []
|
25
28
|
|
26
|
-
@
|
29
|
+
@labels.each do |raw_label|
|
27
30
|
|
28
31
|
col_just, label = just(raw_label)
|
29
32
|
@align_cols << col_just
|
30
|
-
|
33
|
+
labels << label
|
31
34
|
end
|
32
35
|
|
33
36
|
end
|
@@ -35,8 +38,7 @@ class TableFormatter
|
|
35
38
|
#width ||= @maxwidth
|
36
39
|
@width = width
|
37
40
|
@maxwidth = width if width
|
38
|
-
a = @source.map {|x| x.map.
|
39
|
-
labels = @labels
|
41
|
+
a = @source.map {|x| x.map{|y| y.length > 0 ? y : ' ' }}.to_a
|
40
42
|
|
41
43
|
column_widths = widths ? widths : fetch_column_widths(a)
|
42
44
|
|
@@ -55,11 +57,33 @@ class TableFormatter
|
|
55
57
|
|
56
58
|
alias to_s display
|
57
59
|
|
58
|
-
def labels=(a)
|
59
|
-
@raw_labels = a
|
60
|
-
end
|
61
60
|
|
62
61
|
private
|
62
|
+
|
63
|
+
def display_markdown(a, fields)
|
64
|
+
|
65
|
+
print_row = -> (row, widths) do
|
66
|
+
'| ' + row.map\
|
67
|
+
.with_index {|y,i| y.to_s.ljust(widths[i])}.join(' | ') + " |\n"
|
68
|
+
end
|
69
|
+
|
70
|
+
print_thline = -> (row, widths) do
|
71
|
+
'|:' + row.map\
|
72
|
+
.with_index {|y,i| y.to_s.ljust(widths[i])}.join('|:') + "|\n"
|
73
|
+
end
|
74
|
+
|
75
|
+
print_rows = -> (rows, widths) do
|
76
|
+
rows.map {|x| print_row.call(x,widths)}.join
|
77
|
+
end
|
78
|
+
|
79
|
+
widths = ([fields] + a).transpose.map{|x| x.max_by(&:length).length}
|
80
|
+
th = '|' + fields.join('|') + "|\n"
|
81
|
+
th = print_row.call(fields, widths)
|
82
|
+
th_line = print_thline.call widths.map {|x| '-' * (x+1)}, widths
|
83
|
+
|
84
|
+
tb = print_rows.call(a, widths)
|
85
|
+
table = th + th_line + tb
|
86
|
+
end
|
63
87
|
|
64
88
|
def fetch_column_widths(a)
|
65
89
|
|
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
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -12,26 +12,26 @@ cert_chain:
|
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
14
|
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
-
|
15
|
+
8ixkARkWAmV1MB4XDTE2MDcxMjE3MDUyNloXDTE3MDcxMjE3MDUyNlowSDESMBAG
|
16
16
|
A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
|
17
17
|
EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
ggEBAMHvCAviVO+ls3i2lZPbHl982EOKMXIgrIYRWJx/oxjwgdXexyqgfbS7T+fc
|
19
|
+
GxiGxxTBsBv1FU9but4o2QrTiHnk8dqL36lmk6bT3kID+WHg+zOc4RJ5QRCsucCw
|
20
|
+
u7H4C2B+WN/Txy/jJMTJNTz+/5W2kj5oY/2chjl370FvyRZRLQAdjKcrutJzkApQ
|
21
|
+
PtPkqrRBN3d7WZghsRR59OSolUbnkvJ/smFMwwjL8NACq+MTeHZEWoERgJtbk53g
|
22
|
+
JFicdXEoDwwSH1cfHOMt94oDYk8bd17VRWWVl0yNB8b3dJwnZB63fNEJItC/f3nl
|
23
|
+
TS9iIGgUFCTOuPAK36+ibGqPxz0CAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
|
24
|
+
DwQEAwIEsDAdBgNVHQ4EFgQUQunHeoGoIoYOcBq6sJ7U7WmMxCcwJgYDVR0RBB8w
|
25
25
|
HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAD82ILMdg
|
27
|
+
+aSp0sLXD4J3RVxXq4FwEp1qc2YzOD/bq3hjEMOIpaUTn4mDgpBZHTi+Im27abmC
|
28
|
+
IOOExDOuJyMiPf9tqAumOaPkRqLiejQN1C8b6oGM3+iaJJ/RVJRa8RA9FfbwuBWV
|
29
|
+
Ls4X+NVJNZjCGJdfyUVlD+4TvyVqqJw5ZojdZV1Gg4CfweBYq9R674yg41EaeNOh
|
30
|
+
Wo2B+S/H8f/hpJ2VKPkq6jf3l4Qt7/d+cFstruyVfkHotwvGP8Z+Xh3zDrxU6xFg
|
31
|
+
3N7fAlUbFYq1qPg9cSfZni7dwYupZfs1vLjUbKCYyF3LGUR1jnLn4hkP1lFClWwy
|
32
|
+
wGnSddXdhZVZSQ==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
34
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
35
35
|
dependencies: []
|
36
36
|
description:
|
37
37
|
email: james@r0bertson.co.uk
|
@@ -60,8 +60,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
version: '0'
|
61
61
|
requirements: []
|
62
62
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.5.1
|
64
64
|
signing_key:
|
65
65
|
specification_version: 4
|
66
|
-
summary: table-formatter prints a table in plain text format
|
66
|
+
summary: table-formatter prints a table in plain text format or Markdown format from
|
67
|
+
an array
|
67
68
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|