tabulo 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.md +4 -0
- data/README.md +74 -15
- data/VERSION +1 -1
- data/lib/tabulo/table.rb +1 -3
- data/lib/tabulo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2db6b288685b76e7cab29fc52f1f0d265cb77310392449681bd15950231fb3d7
|
4
|
+
data.tar.gz: 8a9477cc4c7f04a0219bac645c774bd5569f1cd2baff5bfb17ffba57e22b497b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 292313dfb4ec2e67e0f0f879c61f9b3797b407d9c8bf1a1e049126b509cedeca557b4cb0d0e4498658438ced29a0faf0aab868ee821cda92a9cea6959a81e75c
|
7
|
+
data.tar.gz: 8714b8dae9a6373d0953a496816e14264af2c78e680b8854866e513776f6aa81827d9beb4c29c190455b3911326495a4cfbe5b712175c54b5087e7927531737b
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Tabulo
|
2
2
|
|
3
3
|
[![Gem Version][GV img]][Gem Version]
|
4
|
+
[![Documentation][DC img]][Documentation]
|
4
5
|
[![Coverage Status][CS img]][Coverage Status]
|
5
6
|
[![Build Status][BS img]][Build Status]
|
7
|
+
[![Code Climate][CC img]][Code Climate]
|
6
8
|
|
7
9
|
## Overview
|
8
10
|
|
@@ -29,9 +31,9 @@ end
|
|
29
31
|
|
30
32
|
## Features
|
31
33
|
|
32
|
-
* A [DRY interface](#configuring-columns)
|
33
|
-
|
34
|
-
*
|
34
|
+
* A [DRY interface](#configuring-columns): by being "column based", it is designed to spare the
|
35
|
+
developer the burden of syncing the ordering within the header row with that of the body rows.
|
36
|
+
* Lets you set [fixed column widths](#fixed-column-widths), then either [wrap](#overflow-handling) or
|
35
37
|
[truncate](#overflow-handling) the overflow.
|
36
38
|
* Alternatively, [shrinkwrap](#shrinkwrap) the table so that each column is just wide enough for its contents.
|
37
39
|
* Put an upper limit on total table width when shrinkwrapping, to
|
@@ -44,10 +46,11 @@ end
|
|
44
46
|
printing as you go, without waiting for the entire underlying collection to load.
|
45
47
|
* Each `Tabulo::Row` is also an `Enumerable`, [providing access](#accessing-cell-values) to the underlying cell values.
|
46
48
|
* Tabulate any `Enumerable`: the underlying collection need not be an array.
|
49
|
+
* [Customize](#additional-configuration-options) border and divider characters.
|
47
50
|
|
48
51
|
Tabulo has also been ported to Crystal (with some modifications): see [Tablo](https://github.com/hutou/tablo).
|
49
52
|
|
50
|
-
##
|
53
|
+
## Contents
|
51
54
|
|
52
55
|
* [Overview](#overview)
|
53
56
|
* [Features](#features)
|
@@ -59,12 +62,13 @@ Tabulo has also been ported to Crystal (with some modifications): see [Tablo](ht
|
|
59
62
|
* [Cell alignment](#cell-alignment)
|
60
63
|
* [Column width, wrapping and truncation](#column-width-wrapping-and-truncation)
|
61
64
|
* [Configuring fixed widths](#configuring-fixed-widths)
|
65
|
+
* [Configuring padding](#configuring-padding)
|
62
66
|
* [Automating column widths](#automating-column-widths)
|
63
67
|
* [Overflow handling](#overflow-handling)
|
64
68
|
* [Formatting cell values](#formatting-cell-values)
|
65
69
|
* [Repeating headers](#repeating-headers)
|
66
70
|
* [Using a Table Enumerator](#using-a-table-enumerator)
|
67
|
-
* [Accessing cell values
|
71
|
+
* [Accessing cell values](#accessing-cell-values)
|
68
72
|
* [Additional configuration options](#additional-configuration-options)
|
69
73
|
* [Development](#development)
|
70
74
|
* [Contributing](#contributing)
|
@@ -202,7 +206,10 @@ table = Tabulo::Table.new([1, 2], columns: %i[itself even?], column_width: 6)
|
|
202
206
|
|
203
207
|
Widths set for individual columns always override the default column width for the table.
|
204
208
|
|
205
|
-
|
209
|
+
<a name="configuring-padding"></a>
|
210
|
+
#### Configuring padding
|
211
|
+
|
212
|
+
The single character of padding either side of each column is not counted in the column width.
|
206
213
|
The amount of this padding can be configured for the table as a whole, using the `column_padding`
|
207
214
|
option passed to `Table.new`.
|
208
215
|
|
@@ -329,7 +336,7 @@ end
|
|
329
336
|
```
|
330
337
|
|
331
338
|
```
|
332
|
-
puts table
|
339
|
+
> puts table
|
333
340
|
+--------------+--------------+
|
334
341
|
| N | Reciprocal |
|
335
342
|
+--------------+--------------+
|
@@ -423,6 +430,25 @@ table.each do |row|
|
|
423
430
|
end
|
424
431
|
```
|
425
432
|
|
433
|
+
The first argument to `add_column`, considered as a `Symbol`, always provides the key
|
434
|
+
for the purpose of accessing the `Hash` form of a `Tabulo::Row`. This key serves as
|
435
|
+
a sort of "logical label" for the column; and it need not be the same as the column
|
436
|
+
header. If we want the header to be different to the label, we can achieve this
|
437
|
+
using the `header` option to `add_column`:
|
438
|
+
|
439
|
+
```ruby
|
440
|
+
table = Tabulo::Table.new(1..5) do |t|
|
441
|
+
t.add_column("Number") { |n| n }
|
442
|
+
t.add_column(:doubled, header: "Number X 2") { |n| n * 2 }
|
443
|
+
end
|
444
|
+
|
445
|
+
table.each do |row|
|
446
|
+
cells = row.to_h
|
447
|
+
puts cells[:Number] # 1...2...3...4...5
|
448
|
+
puts cells[:doubled] # 2...4...6...8...10
|
449
|
+
end
|
450
|
+
```
|
451
|
+
|
426
452
|
### Additional configuration options
|
427
453
|
|
428
454
|
The characters used for horizontal dividers, vertical dividers and corners, which default to `-`,
|
@@ -432,15 +458,44 @@ The characters used for horizontal dividers, vertical dividers and corners, whic
|
|
432
458
|
The character used to indicate truncation, which defaults to `~`, can be configured using the
|
433
459
|
`truncation_indicator` option passed to `Table.new`.
|
434
460
|
|
435
|
-
|
461
|
+
A bottom border can be added to the table when printing, as follows:
|
462
|
+
|
463
|
+
```ruby
|
464
|
+
puts table
|
465
|
+
puts table.horizontal_rule
|
466
|
+
```
|
467
|
+
|
468
|
+
This will output a bottom border that's appropriately sized for the table.
|
436
469
|
|
437
|
-
|
438
|
-
|
439
|
-
|
470
|
+
This mechanism can also be used to output a horizontal divider after each row:
|
471
|
+
|
472
|
+
```ruby
|
473
|
+
table = Tabulo::Table.new(1..3, columns: %i[itself even?])
|
474
|
+
```
|
475
|
+
|
476
|
+
```
|
477
|
+
> table.each { |row| puts row ; puts table.horizontal_rule }
|
478
|
+
+--------------+--------------+
|
479
|
+
| itself | even? |
|
480
|
+
+--------------+--------------+
|
481
|
+
| 1 | false |
|
482
|
+
+--------------+--------------+
|
483
|
+
| 2 | true |
|
484
|
+
+--------------+--------------+
|
485
|
+
| 3 | false |
|
486
|
+
+--------------+--------------+
|
487
|
+
```
|
440
488
|
|
441
489
|
## Contributing
|
442
490
|
|
443
|
-
|
491
|
+
Issues and pull requests are welcome on GitHub at https://github.com/matt-harvey/tabulo.
|
492
|
+
|
493
|
+
To start working on Tabulo, `git clone` and `cd` into your fork of the repo, then run `bin/setup` to
|
494
|
+
install dependencies.
|
495
|
+
|
496
|
+
`bin/console` will give you an interactive prompt that will allow you to experiment; and `rake spec`
|
497
|
+
will run the test suite. For a list of other Rake tasks that are available in the development
|
498
|
+
environment, run `rake -T`.
|
444
499
|
|
445
500
|
## License
|
446
501
|
|
@@ -448,9 +503,13 @@ The gem is available as open source under the terms of the [MIT
|
|
448
503
|
License](http://opensource.org/licenses/MIT).
|
449
504
|
|
450
505
|
[Gem Version]: https://rubygems.org/gems/tabulo
|
506
|
+
[Documentation]: http://www.rubydoc.info/gems/tabulo/1.2.2
|
451
507
|
[Build Status]: https://travis-ci.org/matt-harvey/tabulo
|
452
508
|
[Coverage Status]: https://coveralls.io/r/matt-harvey/tabulo
|
509
|
+
[Code Climate]: https://codeclimate.com/github/matt-harvey/tabulo
|
453
510
|
|
454
|
-
[GV img]: https://img.shields.io/gem/v/tabulo.svg
|
455
|
-
[
|
456
|
-
[
|
511
|
+
[GV img]: https://img.shields.io/gem/v/tabulo.svg
|
512
|
+
[DC img]: https://img.shields.io/badge/documentation-v1.2.2-blue.svg
|
513
|
+
[BS img]: https://img.shields.io/travis/matt-harvey/tabulo.svg
|
514
|
+
[CS img]: https://img.shields.io/coveralls/matt-harvey/tabulo.svg
|
515
|
+
[CC img]: https://codeclimate.com/github/matt-harvey/tabulo/badges/gpa.svg
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.2
|
data/lib/tabulo/table.rb
CHANGED
@@ -237,9 +237,7 @@ module Tabulo
|
|
237
237
|
return self if column_registry.none?
|
238
238
|
columns = column_registry.values
|
239
239
|
|
240
|
-
columns.each
|
241
|
-
column.width = wrapped_width(column.header)
|
242
|
-
end
|
240
|
+
columns.each { |column| column.width = wrapped_width(column.header) }
|
243
241
|
|
244
242
|
@sources.each do |source|
|
245
243
|
columns.each do |column|
|
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: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Harvey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|