table-formatter 0.4.4 → 0.4.5

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
  SHA1:
3
- metadata.gz: b35b9c4184256a1e3676376a16352e7bd9e5efb1
4
- data.tar.gz: 3cddeacb53c39e1db4084d1e4b7620c0e6e6cae9
3
+ metadata.gz: 3e6353a2265f8f3d4082fe28c9c5618ae040c4e6
4
+ data.tar.gz: a00e6ec5d1e56f1b0937303431251978593033c8
5
5
  SHA512:
6
- metadata.gz: 7e18dd0e446c264bf1954a125ac42e2bd506e53bb507931f7836da71f13cf94dad446251958a9a2a87b5aaa01f889948fce653a965ee7b83079bd0652bb7279a
7
- data.tar.gz: ee89f578d47729e137ddc4ff2d5f61654844248d697d70d685002ebc59b7eae4be2782c4849b98503c5103d0c0624c61d2c1a4cd9bb50a12083e479148cecb0b
6
+ metadata.gz: c015e6389cc56148354d28b4140ba825f80902e697eca723a80740f7fd7e728a810d73accc10838ccd4dcaa361e1790098f33412c894e0b4241e6c8bcc810baf
7
+ data.tar.gz: 2866aa2a82955308d6f95d3be08a60a2d6a521c57e9eca1d834cd83ded88e5b37f53631fbbae9b2629d540aa5373df8d4a833c6aeabd8197bdd7561c049fcc9c
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -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
- divider: nil, markdown: false, innermarkdown: false)
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(@labels, widths)
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
- table = th + th_line + tb
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
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-01-08 00:00:00.000000000 Z
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