texttable 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/texttable.rb +11 -6
  3. data/texttable.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9952b36c316d6bfb8b99b98c83e6b443e8df7fab62098d48d2106bfaba910762
4
- data.tar.gz: fac19dec457d9b53adbdb11a6f24b39496af73b882ab4abd856039f10c6b07e4
3
+ metadata.gz: daf8fb1088ce9570617aea39c1cbbfa3b4b5819af7013e26c2e4680d1ec2ceb1
4
+ data.tar.gz: 343e38b5ff4ed2cb20076af22bcfaedb00fd70702dcc8654b4169736b87a4768
5
5
  SHA512:
6
- metadata.gz: 55ef3df123eaf0261b9c3962389b667828653ea50430ca31183c51418aedba3047f9522d5e2bb8b666a81263cd283d1bb63e0fbea75ece990b24cc654cc39562
7
- data.tar.gz: 7198b28bdf371c91976476542a5b903f393009a5d2cbadb8ca1ba89911670453d536929588ced94f6d2f84c05335cf7f0a3568a8e008db079d3ae3ae75d13220
6
+ metadata.gz: dfbd834c7999c0c666c39043f2529b31fa4077292aec331541744cb6fc22a841380914435b75c3462647896969d4b8eb6846e72ebdf6cb3878c761f0ac8005a1
7
+ data.tar.gz: 8b401aab5b7df8d12aa883a7c0932cf5e4713889d5a3f63aa59416cfb3e3c15eb9029257819e9e46aa62e7f23a547239cd2e21e52a35ab91990240c950bdd279
@@ -128,15 +128,20 @@ class TextTable
128
128
  def show!(list=nil)
129
129
  meth = list.is_a?(Array) ? list.method(:push) : method(:puts)
130
130
  join = " | "
131
- both = [@cols.keys] + rows
132
- flip = both.transpose
133
- wide = flip.map {|row| row.map {|col| col.to_s.size }.max }
134
- pict = wide.map {|len| "%-#{len}.#{len}s" }.join(join)
131
+ size = @cols.size
132
+ full = [@cols.keys] + rows
133
+ full.each_with_index do |vals, i| # only when asymmetric
134
+ miss = size - vals.size
135
+ full[i] += [nil] * miss if miss > 0
136
+ full[i] = vals[0...size] if miss < 0
137
+ end
138
+ lens = full.map {|r| r.map {|c| c.to_s.size}}.transpose.map(&:max)
139
+ pict = lens.map {|len| "%-#{len}.#{len}s" }.join(join)
135
140
  pict = [join, pict, join].join.strip
136
- line = (pict % ([""] * @cols.size)).tr("| ", "+-")
141
+ line = (pict % ([""] * size)).tr("| ", "+-")
137
142
  seen = -1
138
143
  meth["", line]
139
- both.each do |vals|
144
+ full.each do |vals|
140
145
  meth[pict % vals]
141
146
  meth[line] if (seen += 1) == 0
142
147
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "texttable"
5
- s.version = "1.1.2"
5
+ s.version = "1.1.3"
6
6
  s.author = "Steve Shreeve"
7
7
  s.email = "steve.shreeve@gmail.com"
8
8
  s.summary = "An easy way to work with rows and columns as simple tables"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: texttable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-02 00:00:00.000000000 Z
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem will auto-size based on column widths.
14
14
  email: steve.shreeve@gmail.com