tabulo 0.6.0 → 0.6.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
  SHA1:
3
- metadata.gz: 84dadcb8679194ba436e2e213defc55800771628
4
- data.tar.gz: aa8d2182569ba3a439bce0b82ef8ceeeb36a4b81
3
+ metadata.gz: 1e98d88f8794a4a99a88e7b03ddd98cde4800a1d
4
+ data.tar.gz: 7cd37619d53da0c9914e6dce651dd56cb427d182
5
5
  SHA512:
6
- metadata.gz: 91d583322688d1db9f7c0dd21111f40d039da50fc767c78eecda2d640b75e42bae6478bc73a88b2c0810e1ce20fe35b61c7ad550a00b5c8a261fb2bf9e7c4b34
7
- data.tar.gz: e0cee253d0513f05158b84bacd7c3e40ad0c546e5765b28c726ecab9936d7c67fa5893d032925bb43c28a96bc2002533c218105bf1ac0fdf43de07559b1106ad
6
+ metadata.gz: d8c1ee3777ad66c2e28475798f3d565f830c583110ab02ca47f7bab9308f826cc877487569ce9a9f13b7578e74c9e237998d8c36dbca9016835fdff0dc0f8980
7
+ data.tar.gz: 9782a06e2877da5aa7d6ba3ecb827f5915b217beb50b02f97684705aaf5ce6fb0d9614cbb9a6592c049ad16da7cc09777176349af172059daf7edc4a0abe5d35
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ### v0.6.1
4
+
5
+ * Fix Table#shrinkwrap! handling of newlines within header cell content.
6
+ * README now correctly formatted by rubydoc.info.
7
+
3
8
  ### v0.6.0
4
9
 
5
10
  * Correctly handle newlines in cell content.
data/README.md CHANGED
@@ -29,28 +29,18 @@ end
29
29
 
30
30
  ## Features
31
31
 
32
- * [Fix](#fixed-column-widths) individual column widths, then either [wrap](#overflow-handling) or
33
- [truncate](#overflow-handling) the overflow as you prefer.
34
- * Alternatively, [shrinkwrap](#shrinkwrap) the table so that each column is just wide enough for
35
- its contents.
36
- * You can cap total table width when shrinkwrapping, to [stop it overflowing your terminal](#max-table-width)
37
- horizontally and becoming an unreadable mess.
38
- * Cell content alignment is [configurable](#cell-alignment), but with useful defaults, with numbers
39
- aligned right and strings left.
40
- * Headers are [repeatable](#repeating-headers)
32
+ * Set [fixed widths](#fixed-column-widths) on individual columns, then either [wrap](#overflow-handling) or
33
+ [truncate](#overflow-handling) the overflow.
34
+ * Alternatively, [shrinkwrap](#shrinkwrap) the table so that each column is just wide enough for its
35
+ contents.
36
+ * Put an upper limit on table width when shrinkwrapping, to [stop it overflowing your terminal horizontally](#max-table-width).
37
+ * Alignment of cell content is [configurable](#cell-alignment), but has helpful content-based defaults
38
+ (numbers right, strings left).
39
+ * Headers are [repeatable](#repeating-headers).
41
40
  * Newlines within cell content are correctly handled.
42
- * A `Tabulo::Table` is an `Enumerable`, so you can [step through it](#enumerator) one row at a time,
43
- without having to wait for the entire underlying collection to load.
44
- * Each `Tabulo::Row` is also an `Enumerable`:
45
-
46
- >
47
- ```ruby
48
- table.each do |row|
49
- row.each do |cell|
50
- # cell => 1, 2 ... 2, 4 ... etc.
51
- end
52
- end
53
- ```
41
+ * A `Tabulo::Table` is an `Enumerable`, so you can [step through it](#enumerator) a row at a time,
42
+ printing as you go, without waiting for the entire underlying collection to load.
43
+ * Each `Tabulo::Row` is also an `Enumerable`, providing access to the underlying cell values.
54
44
 
55
45
  ## Installation
56
46
 
data/lib/tabulo/table.rb CHANGED
@@ -178,16 +178,17 @@ module Tabulo
178
178
  def shrinkwrap!(max_table_width: nil)
179
179
  return self if columns.none?
180
180
 
181
- header_widths = columns.map { |c| c.header.length }
181
+ wrapped_width = -> (str) { str.split($/).map(&:length).max || 1 }
182
182
 
183
- column_widths = @sources.inject(header_widths) do |widths, source|
184
- columns.map do |c|
185
- c.formatted_cell_content(source).split($/, -1).map(&:length).max || 1
186
- end.zip(widths).map(&:max)
183
+ columns.each do |column|
184
+ column.width = wrapped_width.call(column.header)
187
185
  end
188
186
 
189
- columns.zip(column_widths).each do |column, width|
190
- column.width = width
187
+ @sources.each do |source|
188
+ columns.each do |column|
189
+ width = wrapped_width.call(column.formatted_cell_content(source))
190
+ column.width = width if width > column.width
191
+ end
191
192
  end
192
193
 
193
194
  if max_table_width
@@ -241,17 +242,20 @@ module Tabulo
241
242
  # Create an array of "cell stacks", each of which is an array of strings that
242
243
  # will be stacked on top of each other to form a wrapped cell.
243
244
  cell_stacks = @columns.map do |column|
244
- column_width = column.width
245
245
 
246
246
  # Get the raw, non-wrapped, non-truncated content of the cell.
247
247
  raw_subcells = yield column
248
248
 
249
- truncated = (wrap_cells_to && (raw_subcells.size > wrap_cells_to))
250
- subcells = (wrap_cells_to ? raw_subcells[0...wrap_cells_to] : raw_subcells)
249
+ num_raw_subcells = raw_subcells.size
250
+ num_wrapped_subcells = (wrap_cells_to || num_raw_subcells)
251
+
252
+ truncated = (num_raw_subcells > num_wrapped_subcells)
253
+ subcells = raw_subcells[0...num_wrapped_subcells]
251
254
 
252
255
  subcells.map.with_index do |subcell, i|
256
+ subcell_truncated = (truncated && (i == subcells.size - 1))
253
257
  lpad = @padding_character
254
- rpad = (truncated && (i == subcells.size - 1) ? @truncation_indicator : @padding_character)
258
+ rpad = (subcell_truncated ? @truncation_indicator : @padding_character)
255
259
  "#{lpad}#{subcell}#{rpad}"
256
260
  end
257
261
  end
@@ -1,3 +1,3 @@
1
1
  module Tabulo
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabulo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Harvey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-01 00:00:00.000000000 Z
11
+ date: 2017-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -140,7 +140,6 @@ files:
140
140
  - LICENSE.txt
141
141
  - README.md
142
142
  - Rakefile
143
- - TODO.md
144
143
  - bin/console
145
144
  - bin/setup
146
145
  - lib/tabulo.rb
data/TODO.md DELETED
@@ -1,3 +0,0 @@
1
- # TODO
2
-
3
- * Fix broken appearance of http://www.rubydoc.info/gems/tabulo/<version> .