tabulo 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +11 -21
- data/lib/tabulo/table.rb +15 -11
- data/lib/tabulo/version.rb +1 -1
- metadata +2 -3
- data/TODO.md +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e98d88f8794a4a99a88e7b03ddd98cde4800a1d
|
4
|
+
data.tar.gz: 7cd37619d53da0c9914e6dce651dd56cb427d182
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8c1ee3777ad66c2e28475798f3d565f830c583110ab02ca47f7bab9308f826cc877487569ce9a9f13b7578e74c9e237998d8c36dbca9016835fdff0dc0f8980
|
7
|
+
data.tar.gz: 9782a06e2877da5aa7d6ba3ecb827f5915b217beb50b02f97684705aaf5ce6fb0d9614cbb9a6592c049ad16da7cc09777176349af172059daf7edc4a0abe5d35
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -29,28 +29,18 @@ end
|
|
29
29
|
|
30
30
|
## Features
|
31
31
|
|
32
|
-
* [
|
33
|
-
[truncate](#overflow-handling) the overflow
|
34
|
-
* Alternatively, [shrinkwrap](#shrinkwrap) the table so that each column is just wide enough for
|
35
|
-
|
36
|
-
*
|
37
|
-
|
38
|
-
|
39
|
-
|
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)
|
43
|
-
|
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
|
-
|
181
|
+
wrapped_width = -> (str) { str.split($/).map(&:length).max || 1 }
|
182
182
|
|
183
|
-
|
184
|
-
|
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
|
-
|
190
|
-
|
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
|
-
|
250
|
-
|
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 = (
|
258
|
+
rpad = (subcell_truncated ? @truncation_indicator : @padding_character)
|
255
259
|
"#{lpad}#{subcell}#{rpad}"
|
256
260
|
end
|
257
261
|
end
|
data/lib/tabulo/version.rb
CHANGED
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.
|
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-
|
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