table-formatter 0.3.1 → 0.4.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/lib/table-formatter.rb +38 -7
- data.tar.gz.sig +0 -0
- 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: 1f6a98e686c8d03b85eb0ba220988a354cd432e3
|
4
|
+
data.tar.gz: 98ec59477c8a5c39fbd879533f2eb4750335fb94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad30b923559dd72717a87ec8451a1f3959fd78c851b9e1ef132efc21192bf9f1c47ab07e4ce1c3af653360952dad38b17e430f57db29d624d2d238c79a9238a3
|
7
|
+
data.tar.gz: 1c63d521280423e4b66f91b7eb4d37f4ad0f29be0ade538c117466015be1a7deecafd02a937b4d03d23b5a97c77ce4fbed32fd45ae1616db777ccb4ec9e19698
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/table-formatter.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
class TableFormatter
|
6
6
|
|
7
|
-
attr_accessor :source, :labels, :border, :divider, :markdown
|
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)
|
@@ -20,10 +20,30 @@ class TableFormatter
|
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def justify(s, ajust)
|
24
|
+
|
25
|
+
a = s.split('|')
|
24
26
|
|
25
|
-
|
27
|
+
a2 = ajust.map.with_index do |x,i|
|
28
|
+
|
29
|
+
s = a[i+1]
|
30
|
+
|
31
|
+
case x
|
32
|
+
when :r
|
33
|
+
'-' * (s.length - 1) + ':'
|
34
|
+
when :l
|
35
|
+
':' + '-' * (s.length - 1)
|
36
|
+
when
|
37
|
+
':' + '-' * (s.length - 2) + ':'
|
38
|
+
end
|
39
|
+
end
|
26
40
|
|
41
|
+
"|%s|\n" % a2.join('|')
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def display(width=nil, widths: nil, markdown: @markdown)
|
46
|
+
|
27
47
|
if @labels then
|
28
48
|
|
29
49
|
@align_cols, labels = [], []
|
@@ -36,6 +56,12 @@ class TableFormatter
|
|
36
56
|
end
|
37
57
|
|
38
58
|
end
|
59
|
+
|
60
|
+
@col_justify = @align_cols.map do |col|
|
61
|
+
{ljust: :l, rjust: :r, center: :c}[col]
|
62
|
+
end
|
63
|
+
|
64
|
+
return display_markdown(@source, labels) if markdown
|
39
65
|
|
40
66
|
#width ||= @maxwidth
|
41
67
|
@width = width
|
@@ -65,8 +91,11 @@ class TableFormatter
|
|
65
91
|
def display_markdown(a, fields)
|
66
92
|
|
67
93
|
print_row = -> (row, widths) do
|
68
|
-
|
69
|
-
|
94
|
+
|
95
|
+
'| ' + row.map.with_index do |y,i|
|
96
|
+
align = @align_cols ? @align_cols[i] : :ljust
|
97
|
+
y.to_s.method(align).call(widths[i])
|
98
|
+
end.join(' | ') + " |\n"
|
70
99
|
end
|
71
100
|
|
72
101
|
print_thline = -> (row, widths) do
|
@@ -83,8 +112,10 @@ class TableFormatter
|
|
83
112
|
th = print_row.call(fields, widths)
|
84
113
|
th_line = print_thline.call widths.map {|x| '-' * (x+1)}, widths
|
85
114
|
|
115
|
+
th_line2 = justify(th_line, @col_justify)
|
116
|
+
|
86
117
|
tb = print_rows.call(a, widths)
|
87
|
-
table = th +
|
118
|
+
table = th + th_line2 + tb
|
88
119
|
end
|
89
120
|
|
90
121
|
def fetch_column_widths(a)
|
@@ -153,7 +184,7 @@ class TableFormatter
|
|
153
184
|
end
|
154
185
|
|
155
186
|
def just(x)
|
156
|
-
|
187
|
+
|
157
188
|
case x
|
158
189
|
when /^:.*:$/
|
159
190
|
[:center, x[1..-2]]
|
data.tar.gz.sig
CHANGED
Binary file
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
3N7fAlUbFYq1qPg9cSfZni7dwYupZfs1vLjUbKCYyF3LGUR1jnLn4hkP1lFClWwy
|
32
32
|
wGnSddXdhZVZSQ==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2016-07
|
34
|
+
date: 2016-11-07 00:00:00.000000000 Z
|
35
35
|
dependencies: []
|
36
36
|
description:
|
37
37
|
email: james@r0bertson.co.uk
|
metadata.gz.sig
CHANGED
Binary file
|