table-formatter 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99bff45abbcb0e6f020804352e4faa54beea585bdac75ba2e4ae7f9849b79b32
4
- data.tar.gz: 4b94ff40326c1330dcd0f92d73676886d8be8ae37de72d79dce9bb3793515a22
3
+ metadata.gz: c7e3972d61d31bb0e5f4a8530f98bf4a76f8000985e0fddc646d200df5c3bd8c
4
+ data.tar.gz: c12315a1c23b7900bfa0afc3150948cccd7072c50643d2089ca156d5f9a52937
5
5
  SHA512:
6
- metadata.gz: 486bda4aa80ad85c1baeda484d2093491eb23aa06eb06ac63e8bf1e5cd7b863ef6876bb7de7d2664ad75cd6c1043546ff95e248e218c75d5d22a9d403105b6a2
7
- data.tar.gz: 49986df1c497eabc6642d3955d5b7a577c42c61a20b5b030165ec617bfb5452de4c2b4762377b2174f5cb27b42e13b95c79996e182c0d70df8e5bb50a4f451d4
6
+ metadata.gz: ecb25c9968b96b7d472bae86d05aac743756ad20f974b70732fb672cc3430a7102b9535ebecda1f21740a69dc0ad736596e25afa4eb1eb8a7e79bd1649392efc
7
+ data.tar.gz: 4215518c58acfe6e2513b30cfc65fa4b3090ef38f8b17e2e78bbebf9b386665cde4d8eee424abd877697eff7e529456f94b1617a88aee65736428d154e3426a3
checksums.yaml.gz.sig CHANGED
Binary file
@@ -9,8 +9,8 @@ class TableFormatter
9
9
  using ColouredText
10
10
 
11
11
  attr_accessor :source, :labels, :border, :divider, :markdown, :col_justify
12
-
13
- def initialize(source: nil, labels: nil, border: true, wrap: true,
12
+
13
+ def initialize(source: nil, labels: nil, border: true, wrap: true,
14
14
  divider: nil, markdown: false, innermarkdown: false, debug: false)
15
15
 
16
16
  super()
@@ -23,15 +23,15 @@ class TableFormatter
23
23
  @markdown = markdown
24
24
  @innermarkdown = innermarkdown
25
25
  @debug = debug
26
-
26
+
27
27
  end
28
-
28
+
29
29
  def justify(s, ajust)
30
-
30
+
31
31
  a = s.split('|')
32
-
32
+
33
33
  a2 = ajust.map.with_index do |x,i|
34
-
34
+
35
35
  s = a[i+1]
36
36
 
37
37
  case x
@@ -44,15 +44,15 @@ class TableFormatter
44
44
  end
45
45
  end
46
46
 
47
- "|%s|\n" % a2.join('|')
47
+ "|%s|\n" % a2.join('|')
48
48
 
49
49
  end
50
-
50
+
51
51
  def display(width=nil, widths: nil, markdown: @markdown)
52
-
52
+
53
53
  @align_cols = []
54
54
  @labels ||= [''] * @source.first.length
55
-
55
+
56
56
  if @labels then
57
57
 
58
58
  labels = []
@@ -69,7 +69,7 @@ class TableFormatter
69
69
  {ljust: :l, rjust: :r, center: :c}[col]
70
70
  end
71
71
 
72
- return display_markdown(@source, labels) if markdown
72
+ return display_markdown(@source, labels) if markdown
73
73
 
74
74
  #width ||= @maxwidth
75
75
  @width = width
@@ -86,7 +86,7 @@ class TableFormatter
86
86
 
87
87
  div = (border == true ? '-' : '') * records[0].length + "\n"
88
88
  label_buffer = ''
89
-
89
+
90
90
  label_buffer = format_cols(labels, column_widths) + "\n" + div if labels
91
91
 
92
92
  div + label_buffer + records.join("\n") + "\n" + div
@@ -97,35 +97,35 @@ class TableFormatter
97
97
 
98
98
 
99
99
  private
100
-
101
- def display_markdown(a, fields)
102
-
100
+
101
+ def display_markdown(a, fields)
102
+
103
103
  print_row = -> (row, widths) do
104
104
  '| ' + row.map\
105
105
  .with_index {|y,i| y.to_s.ljust(widths[i])}.join(' | ') + " |\n"
106
- end
106
+ end
107
107
 
108
108
  print_thline = -> (row, widths) do
109
109
  '|:' + row.map\
110
110
  .with_index {|y,i| y.to_s.ljust(widths[i])}.join('|:') + "|\n"
111
111
  end
112
-
112
+
113
113
  if @debug then
114
-
114
+
115
115
  puts '@labels: ' + @labels.inspect
116
116
  puts 'thline: ' + print_thline.inspect
117
-
117
+
118
118
  end
119
-
119
+
120
120
  print_rows = -> (rows, widths) do
121
121
  rows.map {|x| print_row.call(x,widths)}.join
122
122
  end
123
123
 
124
-
124
+
125
125
  raw_vals = a
126
126
 
127
127
  # create Markdown hyperlinks for any URLs
128
-
128
+
129
129
  vals = raw_vals.map do |row|
130
130
 
131
131
  row.map do |col|
@@ -141,49 +141,49 @@ class TableFormatter
141
141
  url_title = (a.join('.') + path)[0..39] + '...'
142
142
 
143
143
  "[%s](%s)" % [url_title, col]
144
-
144
+
145
145
  else
146
-
147
- if @innermarkdown then
148
- "{::nomarkdown}" +
146
+
147
+ if @innermarkdown then
148
+ "{::nomarkdown}" +
149
149
  RDiscount.new(col).to_html.strip.gsub("\n",'') + "{:/}"
150
150
  else
151
151
 
152
152
  col
153
-
153
+
154
154
  end
155
-
155
+
156
156
  end
157
-
157
+
158
158
  r
159
159
  end
160
- end
160
+ end
161
161
 
162
162
  puts ('fields: ' + fields.inspect).debug if @debug
163
163
  if fields then
164
- widths = ([(fields + ['']).take(a.first.length)] +
164
+ widths = ([(fields + ['']).take(a.first.length)] +
165
165
  vals).transpose.map{|x| x.max_by(&:length).length}
166
166
  end
167
167
 
168
- th = if @labels.map(&:strip).join.length > 0 then
168
+ th = if @labels.map(&:strip).join.length > 0 then
169
169
  print_row.call(fields, widths)
170
170
  else
171
171
  ''
172
172
  end
173
-
174
- th_line = print_thline.call widths.map {|x| '-' * (x+1)}, widths
175
- tb = print_rows.call(vals, widths)
176
- th_line2 = justify(th_line, @col_justify)
177
-
178
- table = th + th_line2 + tb
173
+
174
+ th_line = print_thline.call widths.map {|x| '-' * (x+1)}, widths
175
+ tb = print_rows.call(vals, widths)
176
+ th_line2 = justify(th_line, @col_justify)
177
+
178
+ table = th + th_line2 + tb
179
179
  end
180
180
 
181
181
  def display_markdown2(a, fields)
182
-
182
+
183
183
  print_row = -> (row, widths) do
184
-
185
- '| ' + row.map.with_index do |y,i|
186
- align = @align_cols ? @align_cols[i] : :ljust
184
+
185
+ '| ' + row.map.with_index do |y,i|
186
+ align = @align_cols ? @align_cols[i] : :ljust
187
187
  y.to_s.method(align).call(widths[i])
188
188
  end.join(' | ') + " |\n"
189
189
  end
@@ -207,9 +207,9 @@ class TableFormatter
207
207
  tb = print_rows.call(a, widths)
208
208
  table = th + th_line2 + tb
209
209
  end
210
-
210
+
211
211
  def fetch_column_widths(a)
212
-
212
+
213
213
  puts 'a: ' + a.inspect if @debug
214
214
  d = tabulate(a).map &:flatten
215
215
  puts 'd: ' + d.inspect if @debug
@@ -217,16 +217,18 @@ class TableFormatter
217
217
  d.map{|x| x.max_by(&:length).length}
218
218
 
219
219
  end
220
-
220
+
221
221
  def format_cols(row, col_widths, bar='')
222
222
 
223
- outer_bar, inner_spacer = '', ''
224
- (outer_bar = bar = '|'; inner_spacer = ' ') if border == true
223
+ outer_bar = ''
224
+ inner_spacer = border ? ' ' : ''
225
+ outer_bar = border ? '|' : ''
226
+ #(outer_bar = bar = '|'; inner_spacer = ' ') if border == true
225
227
  col_spacer = @divider ? 0 : 2
226
-
228
+
227
229
  buffer = outer_bar
228
230
 
229
-
231
+
230
232
  row.each_with_index do |col, i|
231
233
 
232
234
  align = @align_cols.any? ? @align_cols[i] : :ljust
@@ -238,45 +240,46 @@ class TableFormatter
238
240
  end
239
241
 
240
242
  buffer += inner_spacer + val + next_bar.to_s
241
- end
242
-
243
+ puts 'buffer: ' + buffer.inspect if @debug
244
+ end
245
+
243
246
  buffer
244
247
 
245
- end
248
+ end
246
249
 
247
250
  def format_rows(raw_a, col_widths)
248
251
 
249
252
  @width = col_widths.inject(&:+)
250
253
 
251
254
  col_widths[-1] -= col_widths.inject(&:+) - @maxwidth if @width > @maxwidth
252
-
255
+
253
256
  a = if @wrap == true then
254
-
257
+
255
258
  raw_a.map do |raw_row|
256
259
 
257
260
  rowx = raw_row.map.with_index do |col, i|
258
261
  col.chars.each_slice(col_widths[i]).map(&:join)
259
- end
260
-
262
+ end
263
+
261
264
  max_len = rowx.max_by {|x| x.length}.length
262
-
263
- rowx.each do |x|
265
+
266
+ rowx.each do |x|
264
267
  len = x.length
265
268
  x.concat ([''] * (max_len - len)) if len < max_len
266
269
  end
267
-
270
+
268
271
  rowx.transpose
269
272
  end.flatten(1)
270
273
  else
271
274
  raw_a
272
275
  end
273
-
276
+
274
277
  a.map {|row| format_cols(row, col_widths, divider) }
275
278
 
276
279
  end
277
280
 
278
281
  def just(x)
279
-
282
+
280
283
  case x
281
284
  when /^:.*:$/
282
285
  [: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.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -11,31 +11,31 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwMzExMTIxMzQ5WhcN
15
- MjAwMzEwMTIxMzQ5WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDbAPHx
17
- 9x7v9jaB9u2bLGAvjFXxLNOHvdjM2WdnhNF9n3fOXyLbLNCSGpL4gPdZpdlAWtJO
18
- InGKmese3mSkXGJa5MPWvQ2J14KJIbMoBoNoVicH0dDu2A52vnSBcUFCU2UffqYz
19
- nw2FoYsKwMD05brtuCtuVIPpDa9wCwqs6Jlbz8hnsP1QKJp0uUn1WvgLaHtnM7GU
20
- W95nK1W7uS9/DRtQ6PV69aYtfPNv+7fBDvhKnouycTWKuLNpfvxDYsHMofGAZDfN
21
- f+yzj2T+JqKauqr0Tn4MfHZFnAOxRsHPxk/CaqnBD18vU9AzPjQWb+nPI0gBZQwI
22
- MtLZSUuIbUwVCurx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 nZZZo4Tie4hpHvjlAc0j0gbLrjIi7RrZU6qVzYwAm/kbe0GcssatoUGXJt5Xc7PP
33
+ S35fv/YUDZBVcNxhMXRlxrwt3HQOWTJ4OgPbmUy3mECUiwS4zmd6gMBB4fnHu8Co
34
+ TtQHVdjMbM3o4LP7R8QX2j3EnNZujKWpnDV+rD584HGXY9KQJkyf3t/lhNFHrK+c
35
+ l3i5J/pMO13Qwr0Pdbd4P0pc/8KEBKZelhuzCHkpFbe0QjLtR5QEiQ50B6CZeLAx
36
+ 0ZbFvuQZbFmrQk1+kPjecIT9
37
37
  -----END CERTIFICATE-----
38
- date: 2019-05-25 00:00:00.000000000 Z
38
+ date: 2022-02-01 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: c32
@@ -78,7 +78,7 @@ dependencies:
78
78
  - !ruby/object:Gem::Version
79
79
  version: 2.2.0.1
80
80
  description:
81
- email: james@jamesrobertson.eu
81
+ email: digital.robertson@gmail.com
82
82
  executables: []
83
83
  extensions: []
84
84
  extra_rdoc_files: []
@@ -103,7 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.0.1
106
+ rubyforge_project:
107
+ rubygems_version: 2.7.10
107
108
  signing_key:
108
109
  specification_version: 4
109
110
  summary: table-formatter prints a table in plain text format or Markdown format from
metadata.gz.sig CHANGED
Binary file