tabulo 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/CHANGELOG.md +8 -0
- data/README.md +140 -88
- data/VERSION +1 -1
- data/assets/social_media_preview/table.png +0 -0
- data/lib/tabulo/border.rb +56 -101
- data/lib/tabulo/cell.rb +27 -16
- data/lib/tabulo/column.rb +28 -5
- data/lib/tabulo/table.rb +98 -79
- data/lib/tabulo/util.rb +20 -0
- data/lib/tabulo/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9ebd03570ab58159573421765c5fa7260dbaec7a7f573a28b746a2c022dd3c8
|
4
|
+
data.tar.gz: 85c7d4de41779701baceb6db3b0b66b47025f0c3f99a8181f9948306d5f826bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eabf52fe920bdbc2867184f3feee0d03e33f79d101d95b4b96095e390786d8443d22c1ab51a10e5a26645c45687f4a36f18c5dc8b35cc72d9162c90c3fb243cc
|
7
|
+
data.tar.gz: d991da9c53378a981623c5622be156f970f37e6f42a3dd22b02d51b11020e1302a5b5209117a4a6b9d74e36c555f73f0a2f67eb2b6ff2dafcf7b14d172eb2e00
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### v2.6.0
|
4
|
+
|
5
|
+
* Add an additional, optional parameter to `styler`, `header_styler` and `title_styler`
|
6
|
+
callbacks, which will receive the index (0, 1 or etc.) of the line within the cell
|
7
|
+
being styled.
|
8
|
+
* Allow padding to be configured on a column-by-column basis.
|
9
|
+
* Minor documentation improvements.
|
10
|
+
|
3
11
|
### v2.5.0
|
4
12
|
|
5
13
|
* Add option of table title, together with options for styling and aligning the title
|
data/README.md
CHANGED
@@ -7,7 +7,11 @@
|
|
7
7
|
[![Code Climate][CC img]][Code Climate]
|
8
8
|
[![Awesome][AR img]][Awesome Ruby]
|
9
9
|
|
10
|
-
Tabulo is a
|
10
|
+
Tabulo is a Ruby library for generating plain text tables (also known as “terminal tables”
|
11
|
+
or “ASCII tables”). It is both highly configurable and very easy to use.
|
12
|
+
|
13
|
+
<a name="overview"></a>
|
14
|
+
## Overview
|
11
15
|
|
12
16
|
_Quick API:_
|
13
17
|
|
@@ -41,41 +45,39 @@ end
|
|
41
45
|
└────┴────────────┴───────────┘
|
42
46
|
```
|
43
47
|
|
48
|
+
<a name="features"></a>
|
44
49
|
## Features
|
45
50
|
|
46
|
-
* Presents a [DRY
|
47
|
-
|
48
|
-
with that of the body rows.
|
51
|
+
* Presents a [DRY API](#adding-columns) that is column-based, not row-based, meaning header and body rows are
|
52
|
+
automatically in sync
|
49
53
|
* Lets you set [fixed column widths](#fixed-column-widths), then either [wrap](#overflow-handling)
|
50
|
-
or [truncate](#overflow-handling) the overflow
|
51
|
-
* Alternatively,
|
52
|
-
|
53
|
-
*
|
54
|
-
|
55
|
-
* Tabulate any `Enumerable`: the underlying collection need not be an array
|
56
|
-
*
|
57
|
-
|
58
|
-
|
59
|
-
*
|
60
|
-
|
61
|
-
*
|
62
|
-
*
|
63
|
-
*
|
64
|
-
* Apply [colours](#colours-and-styling) and other styling to table content and borders, without breaking the table.
|
65
|
-
* Easily [transpose](#transposition) the table, so that rows are swapped with columns.
|
54
|
+
or [truncate](#overflow-handling) the overflow
|
55
|
+
* Alternatively, [“pack”](#pack) the table so that columns are auto-sized to their
|
56
|
+
contents, but [without overflowing the terminal](#max-table-width)
|
57
|
+
* Cell alignment is [configurable](#cell-alignment), but has helpful content-based defaults (numbers right, strings
|
58
|
+
left)
|
59
|
+
* Tabulate any `Enumerable`: the underlying collection need not be an array
|
60
|
+
* [Step through](#enumerator) your table a row at a time, printing as you go, without waiting for the
|
61
|
+
underlying collection to load. In other words, have a [streaming interface](#enumerator) for free.
|
62
|
+
* Add an optional [title](#title) to your table
|
63
|
+
* The header row can be [repeated](#repeating-headers) at arbitrary intervals
|
64
|
+
* Newlines within cell content are correctly handled
|
65
|
+
* Multibyte Unicode characters are correctly handled
|
66
|
+
* Apply [colours](#colours-and-styling) and other styling to table content and borders, without breaking the table
|
67
|
+
* Easily [transpose](#transposition) the table, so that rows are swapped with columns
|
66
68
|
* Choose from multiple [border configurations](#borders), including Markdown, “ASCII”, and smoothly
|
67
|
-
joined Unicode border characters
|
68
|
-
* Optionally add a [title](#title) to your table.
|
69
|
+
joined Unicode border characters
|
69
70
|
|
70
71
|
Tabulo has also been ported to Crystal (with some modifications): see [Tablo](https://github.com/hutou/tablo).
|
71
72
|
|
73
|
+
<a name="contents"></a>
|
72
74
|
## Contents
|
73
75
|
|
76
|
+
* [Overview](#overview)
|
74
77
|
* [Features](#features)
|
75
78
|
* [Table of contents](#table-of-contents)
|
76
79
|
* [Installation](#installation)
|
77
80
|
* [Detailed usage](#detailed-usage)
|
78
|
-
* [Requiring the gem](#requiring-the-gem)
|
79
81
|
* [Creating a table](#table-initialization)
|
80
82
|
* [Adding columns](#adding-columns)
|
81
83
|
* [Quick API](#quick-api)
|
@@ -90,13 +92,14 @@ Tabulo has also been ported to Crystal (with some modifications): see [Tablo](ht
|
|
90
92
|
* [Automating column widths](#automating-column-widths)
|
91
93
|
* [Configuring padding](#configuring-padding)
|
92
94
|
* [Overflow handling](#overflow-handling)
|
95
|
+
* [Manual cell wrapping](#manual-wrapping)
|
93
96
|
* [Formatting cell values](#formatting-cell-values)
|
94
97
|
* [Colours and other styling](#colours-and-styling)
|
95
98
|
* [Styling cell content](#styling-cell-content)
|
96
99
|
* [Styling column headers](#styling-column-headers)
|
97
100
|
* [Styling the table title](#styling-title)
|
98
101
|
* [Setting default styles](#default-styles)
|
99
|
-
* [Styling borders](#
|
102
|
+
* [Styling borders](#styling-borders)
|
100
103
|
* [Repeating headers](#repeating-headers)
|
101
104
|
* [Using a Table Enumerator](#using-a-table-enumerator)
|
102
105
|
* [Accessing cell values](#accessing-cell-values)
|
@@ -109,7 +112,7 @@ Tabulo has also been ported to Crystal (with some modifications): see [Tablo](ht
|
|
109
112
|
* [Contributing](#contributing)
|
110
113
|
* [License](#license)
|
111
114
|
|
112
|
-
## Installation
|
115
|
+
## Installation [↑](#contents)
|
113
116
|
|
114
117
|
Add this line to your application’s Gemfile:
|
115
118
|
|
@@ -125,16 +128,14 @@ Or install it yourself:
|
|
125
128
|
|
126
129
|
$ gem install tabulo
|
127
130
|
|
128
|
-
|
129
|
-
|
130
|
-
### Requiring the gem
|
131
|
+
To use the gem, you need to require it in your source code as follows:
|
131
132
|
|
132
133
|
```ruby
|
133
134
|
require 'tabulo'
|
134
135
|
```
|
135
136
|
|
136
137
|
<a name="table-initialization"></a>
|
137
|
-
### Creating a table
|
138
|
+
### Creating a table [↑](#contents)
|
138
139
|
|
139
140
|
You instantiate a `Tabulo::Table` by passing it an underlying `Enumerable`, being the collection of
|
140
141
|
things that you want to tabulate. Each member of this collection will end up
|
@@ -149,10 +150,10 @@ other_table = Tabulo::Table.new(User.all)
|
|
149
150
|
For the table to be useful, however, it must also contain columns…
|
150
151
|
|
151
152
|
<a name="adding-columns"></a>
|
152
|
-
### Adding columns
|
153
|
+
### Adding columns [↑](#contents)
|
153
154
|
|
154
155
|
<a name="quick-api"></a>
|
155
|
-
#### Quick API
|
156
|
+
#### Quick API [↑](#contents)
|
156
157
|
|
157
158
|
When the columns correspond to methods on members of the underlying enumerable, you can use
|
158
159
|
the “quick API”, by passing a symbol directly to `Tabulo::Table.new` for each column.
|
@@ -174,7 +175,7 @@ table = Tabulo::Table.new([1, 2, 5], :itself, :even?, :odd?)
|
|
174
175
|
```
|
175
176
|
|
176
177
|
<a name="full-api"></a>
|
177
|
-
#### Full API
|
178
|
+
#### Full API [↑](#contents)
|
178
179
|
|
179
180
|
Columns can also be added to the table one-by-one using `add_column`. This “full API” is
|
180
181
|
more verbose, but provides greater configurability:
|
@@ -243,7 +244,7 @@ end
|
|
243
244
|
```
|
244
245
|
|
245
246
|
<a name="labels-headers"></a>
|
246
|
-
#### Column labels _vs_ headers
|
247
|
+
#### Column labels _vs_ headers [↑](#contents)
|
247
248
|
|
248
249
|
The first argument to `add_column` is the called the _label_ for that column. It serves as the
|
249
250
|
column’s unique identifier: only one column may have a given label per table.
|
@@ -257,7 +258,7 @@ table.add_column(:itself2, header: "N", &:itself) # header need not be unique
|
|
257
258
|
```
|
258
259
|
|
259
260
|
<a name="column-positioning"></a>
|
260
|
-
#### Positioning columns
|
261
|
+
#### Positioning columns [↑](#contents)
|
261
262
|
|
262
263
|
By default, each new column is added to the right of all the other columns so far added to the
|
263
264
|
table. However, if you want to insert a new column into some other position, you can use the
|
@@ -280,7 +281,7 @@ table.add_column(:even?, before: :odd?)
|
|
280
281
|
```
|
281
282
|
|
282
283
|
<a name="removing-columns"></a>
|
283
|
-
### Removing columns
|
284
|
+
### Removing columns [↑](#contents)
|
284
285
|
|
285
286
|
There is also a `#remove_column` method, for deleting an existing column from a table. Pass it
|
286
287
|
the label of the column you want to remove:
|
@@ -290,13 +291,12 @@ table.remove_column(:even?)
|
|
290
291
|
```
|
291
292
|
|
292
293
|
<a name="title"></a>
|
293
|
-
### Adding a title
|
294
|
+
### Adding a title [↑](#contents)
|
294
295
|
|
295
|
-
You can
|
296
|
+
You can give your table a title, using the `title` option:
|
296
297
|
|
297
298
|
```ruby
|
298
|
-
table = Tabulo::Table.new([1, 2, 3], :itself, :odd?, title: "Numbers")
|
299
|
-
table.add_column(:even?, before: :odd?)
|
299
|
+
table = Tabulo::Table.new([1, 2, 3], :itself, :even?, :odd?, title: "Numbers")
|
300
300
|
```
|
301
301
|
|
302
302
|
```
|
@@ -317,7 +317,7 @@ the rendered table to cease being valid Markdown, as unfortunately almost no mar
|
|
317
317
|
adding a captions (i.e. titles) to tables.
|
318
318
|
|
319
319
|
<a name="cell-alignment"></a>
|
320
|
-
### Cell alignment
|
320
|
+
### Cell alignment [↑](#contents)
|
321
321
|
|
322
322
|
By default, column header text is center-aligned, while the content of each body cell is aligned
|
323
323
|
according to its data type. Numbers are right-aligned, text is left-aligned, and booleans (`false`
|
@@ -344,10 +344,10 @@ If a table title is present, it is center-aligned by default. This can be change
|
|
344
344
|
table = Tabulo::Table.new([1, 2], :itself, :even?, title: "Numbers", align_title: :left)
|
345
345
|
```
|
346
346
|
|
347
|
-
### Column width, wrapping and truncation
|
347
|
+
### Column width, wrapping and truncation [↑](#contents)
|
348
348
|
|
349
349
|
<a name="fixed-column-widths"></a>
|
350
|
-
#### Configuring fixed widths
|
350
|
+
#### Configuring fixed widths [↑](#contents)
|
351
351
|
|
352
352
|
By default, column width is fixed at 12 characters, plus 1 character of padding on either side.
|
353
353
|
This can be adjusted on a column-by-column basis using the `width` option of `add_column`:
|
@@ -389,7 +389,7 @@ table = Tabulo::Table.new([1, 2], :itself, :even?, column_width: 6)
|
|
389
389
|
Widths set for individual columns always override the default column width for the table.
|
390
390
|
|
391
391
|
<a name="pack"></a>
|
392
|
-
#### Automating column widths
|
392
|
+
#### Automating column widths [↑](#contents)
|
393
393
|
|
394
394
|
Instead of setting column widths “manually”, you can tell the table to sort out the widths
|
395
395
|
itself, so that each column is just wide enough for its header and contents (plus a character
|
@@ -478,7 +478,7 @@ table itself. There are [ways around this](#freezing-a-table), however, if this
|
|
478
478
|
behaviour—see [below](#freezing-a-table).
|
479
479
|
|
480
480
|
<a name="configuring-padding"></a>
|
481
|
-
#### Configuring padding
|
481
|
+
#### Configuring padding [↑](#contents)
|
482
482
|
|
483
483
|
The single character of padding either side of each column is not counted in the column width.
|
484
484
|
The amount of this extra padding can be configured for the table as a whole, using the `column_padding`
|
@@ -520,8 +520,30 @@ table = Tabulo::Table.new([1, 2, 5], :itself, :even?, :odd?, column_padding: [0,
|
|
520
520
|
+--------------+--------------+--------------+
|
521
521
|
```
|
522
522
|
|
523
|
+
Padding can also be configured on a column-by-column basis, using the `padding` option when calling
|
524
|
+
`add_column`:
|
525
|
+
|
526
|
+
```ruby
|
527
|
+
table = Tabulo::Table.new([1, 2, 5], :itself, :even?)
|
528
|
+
table.add_column(:odd?, padding: 2)
|
529
|
+
```
|
530
|
+
|
531
|
+
```
|
532
|
+
> puts table
|
533
|
+
+--------------+--------------+------------------+
|
534
|
+
| itself | even? | odd? |
|
535
|
+
+--------------+--------------+------------------+
|
536
|
+
| 1 | false | true |
|
537
|
+
| 2 | true | false |
|
538
|
+
| 5 | false | true |
|
539
|
+
+--------------+--------------+------------------+
|
540
|
+
```
|
541
|
+
|
542
|
+
This column-level `padding` setting always overrides any table-level `column_padding` setting, for
|
543
|
+
the column in question.
|
544
|
+
|
523
545
|
<a name="overflow-handling"></a>
|
524
|
-
#### Overflow handling
|
546
|
+
#### Overflow handling [↑](#contents)
|
525
547
|
|
526
548
|
By default, if cell contents exceed their column width, they are wrapped for as many rows as
|
527
549
|
required:
|
@@ -572,8 +594,34 @@ table = Tabulo::Table.new(
|
|
572
594
|
The character used to indicate truncation, which defaults to `~`, can be configured using the
|
573
595
|
`truncation_indicator` option passed to `Table.new`.
|
574
596
|
|
597
|
+
<a name="manual-wrapping"></a>
|
598
|
+
#### Manual cell wrapping [↑](#contents)
|
599
|
+
|
600
|
+
You can “manually” wrap the content of a title, header or body cell at a particular
|
601
|
+
point, simply by placing a newline character at that point:
|
602
|
+
|
603
|
+
```ruby
|
604
|
+
table = Tabulo::Table.new(1..3) do |t|
|
605
|
+
t.add_column("The number\nitself", &:itself)
|
606
|
+
t.add_column("Even?", &:even?)
|
607
|
+
t.add_column("Odd?", &:odd?)
|
608
|
+
end
|
609
|
+
```
|
610
|
+
|
611
|
+
```
|
612
|
+
> puts table
|
613
|
+
+--------------+--------------+--------------+
|
614
|
+
| The number | Even? | Odd? |
|
615
|
+
| itself | | |
|
616
|
+
+--------------+--------------+--------------+
|
617
|
+
| 1 | false | true |
|
618
|
+
| 2 | true | false |
|
619
|
+
| 3 | false | true |
|
620
|
+
+--------------+--------------+--------------+
|
621
|
+
```
|
622
|
+
|
575
623
|
<a name="formatting-cell-values"></a>
|
576
|
-
### Formatting cell values
|
624
|
+
### Formatting cell values [↑](#contents)
|
577
625
|
|
578
626
|
While the callable passed to `add_column` determines the underyling, calculated value in each
|
579
627
|
cell of the column, there is a separate concept, of a “formatter”, that determines how
|
@@ -633,14 +681,14 @@ the table.
|
|
633
681
|
The `formatter` callback also has an alternative, 2-parameter version. If `formatter` is passed
|
634
682
|
a 2-parameter callable, the second parameter will be given a `CellData` instance,
|
635
683
|
containing additional information about the cell that may be useful in determining how to format
|
636
|
-
it—see the [documentation](https://www.rubydoc.info/gems/tabulo/2.
|
684
|
+
it—see the [documentation](https://www.rubydoc.info/gems/tabulo/2.6.0/Tabulo/CellData.html)
|
637
685
|
for details.
|
638
686
|
|
639
687
|
<a name="colours-and-styling"></a>
|
640
|
-
### Colours and other styling
|
688
|
+
### Colours and other styling [↑](#contents)
|
641
689
|
|
642
690
|
<a name="styling-cell-content"></a>
|
643
|
-
#### Styling cell content
|
691
|
+
#### Styling cell content [↑](#contents)
|
644
692
|
|
645
693
|
In most terminals, if you want to print text that is coloured, or has certain other styles such as
|
646
694
|
underlining, you need to use ANSI escape sequences, either directly, or by means of a library such
|
@@ -673,13 +721,13 @@ table.add_column(
|
|
673
721
|
)
|
674
722
|
```
|
675
723
|
|
676
|
-
The `styler` option should be passed a callable that takes either two or
|
677
|
-
first parameter represents the underlying value of the cell (in this case a boolean indicating whether
|
678
|
-
|
679
|
-
content after any processing by the [formatter](#formatting-cell-values)
|
680
|
-
|
681
|
-
|
682
|
-
|
724
|
+
The `styler` option should be passed a callable that takes either two, three or four parameters.
|
725
|
+
The first parameter represents the underlying value of the cell (in this case a boolean indicating whether the
|
726
|
+
number is even). The second parameter represents the formatted string value of that cell, i.e. the cell
|
727
|
+
content after any processing by the [formatter](#formatting-cell-values). The third and fourth
|
728
|
+
parameters are optional, and contain further information about the cell and its contents that may be useful in
|
729
|
+
determining how to style it. See the [documentation](https://www.rubydoc.info/gems/tabulo/2.6.0/Tabulo/CellData.html)
|
730
|
+
for details.
|
683
731
|
|
684
732
|
If the content of a cell is wrapped over multiple lines, then the `styler` will be called once
|
685
733
|
per line, so that each line of the cell will have the escape sequence applied to it separately
|
@@ -689,7 +737,7 @@ If the content of a cell has been [truncated](#overflow-handling), then whatever
|
|
689
737
|
styling apply to the cell content will also be applied the truncation indicator character.
|
690
738
|
|
691
739
|
<a name="styling-column-headers"></a>
|
692
|
-
#### Styling column headers
|
740
|
+
#### Styling column headers [↑](#contents)
|
693
741
|
|
694
742
|
If you want to apply colours or other styling to the content of a column header, as opposed
|
695
743
|
to cells in the table body, use the `header_styler` option, e.g.:
|
@@ -698,22 +746,36 @@ to cells in the table body, use the `header_styler` option, e.g.:
|
|
698
746
|
table.add_column(:even?, header_styler: -> (s) { "\033[32m#{s}\033[0m" })
|
699
747
|
```
|
700
748
|
|
701
|
-
The `header_styler` option accepts
|
702
|
-
[documentation](https://www.rubydoc.info/gems/tabulo/2.
|
749
|
+
The `header_styler` option accepts a 1-, 2- or 3-parameter callable. See the
|
750
|
+
[documentation](https://www.rubydoc.info/gems/tabulo/2.6.0/Tabulo/Table#add_column-instance_method)
|
703
751
|
for details.
|
704
|
-
```
|
705
752
|
|
706
753
|
<a name="styling-title"></a>
|
707
|
-
#### Styling the table title
|
754
|
+
#### Styling the table title [↑](#contents)
|
708
755
|
|
709
756
|
To apply colours or other styling to the table title, if present, use the `title_styler` option
|
710
757
|
when initializing the table. This accepts a single-parameter callable:
|
711
758
|
|
712
759
|
```ruby
|
713
760
|
table = Tabulo::Table.new(1..5, :itself, :even?, :odd?, title: "Numbers", title_styler: -> (s) { "\033[32m#{s}\033[0m" })
|
761
|
+
```
|
762
|
+
|
763
|
+
The `title_styler` option accepts a 1- or 2-parameter callable. See the
|
764
|
+
[documentation](https://www.rubydoc.info/gems/tabulo/2.6.0/Tabulo/Table#initialize-instance_method)
|
765
|
+
for details.
|
766
|
+
|
767
|
+
<a name="styling-borders"></a>
|
768
|
+
#### Styling borders [↑](#contents)
|
769
|
+
|
770
|
+
Styling can also be applied to borders and dividing lines, using the `border_styler` option when
|
771
|
+
initializing the table, e.g.:
|
772
|
+
|
773
|
+
```ruby
|
774
|
+
table = Tabulo::Table.new(1..5, :itself, :even?, :odd?, border_styler: -> (s) { "\033[32m#{s}\033[0m" })
|
775
|
+
```
|
714
776
|
|
715
777
|
<a name="default-styles"></a>
|
716
|
-
#### Setting default styles
|
778
|
+
#### Setting default styles [↑](#contents)
|
717
779
|
|
718
780
|
By default, no styling is applied to the headers or body content of a column unless configured to do
|
719
781
|
so via the `header_styler` or `styler` option when calling `add_column` for that particular column.
|
@@ -725,21 +787,11 @@ in the table to be green, you could do:
|
|
725
787
|
table = Tabulo::Table.new(1..5, :itself, :even?, :odd?, header_styler: -> (s) { "\033[32m#{s}\033[0m" })
|
726
788
|
```
|
727
789
|
|
728
|
-
Now, all columns in the table will
|
729
|
-
|
730
|
-
|
731
|
-
<a name="border-styling"></a>
|
732
|
-
#### Styling borders
|
733
|
-
|
734
|
-
Styling can also be applied to borders and dividing lines, using the `border_styler` option when
|
735
|
-
initializing the table, e.g.:
|
736
|
-
|
737
|
-
```ruby
|
738
|
-
table = Tabulo::Table.new(1..5, :itself, :even?, :odd?, border_styler: -> (s) { "\033[32m#{s}\033[0m" })
|
739
|
-
```
|
790
|
+
Now, all columns in the table will automatically have green header text, unless overridden by another
|
791
|
+
header styler being passed to `#add_column`.
|
740
792
|
|
741
793
|
<a name="repeating-headers"></a>
|
742
|
-
### Repeating headers
|
794
|
+
### Repeating headers [↑](#contents)
|
743
795
|
|
744
796
|
By default, headers are only shown once, at the top of the table (`header_frequency: :start`). If
|
745
797
|
`header_frequency` is passed `nil`, headers are not shown at all; or, if passed an `Integer` N,
|
@@ -776,7 +828,7 @@ table = Tabulo::Table.new(1..10, :itself, :even?, header_frequency: 5)
|
|
776
828
|
Note that if the table has a [title](#title), it will not be repeated; only column headers are repeated.
|
777
829
|
|
778
830
|
<a name="enumerator"></a>
|
779
|
-
### Using a Table Enumerator
|
831
|
+
### Using a Table Enumerator [↑](#contents)
|
780
832
|
|
781
833
|
Because it’s an `Enumerable`, a `Tabulo::Table` can also give you an `Enumerator`,
|
782
834
|
which is useful when you want to step through rows one at a time. In a Rails console,
|
@@ -805,7 +857,7 @@ in that case the entire collection must be traversed up front in order for colum
|
|
805
857
|
calculated.)
|
806
858
|
|
807
859
|
<a name="accessing-cell-values"></a>
|
808
|
-
### Accessing cell values
|
860
|
+
### Accessing cell values [↑](#contents)
|
809
861
|
|
810
862
|
Each `Tabulo::Table` is an `Enumerable` of which each element is a `Tabulo::Row`. Each `Tabulo::Row`
|
811
863
|
is itself an `Enumerable`, of `Tabulo::Cell`. The `Tabulo::Cell#value` method will return the
|
@@ -841,7 +893,7 @@ end
|
|
841
893
|
```
|
842
894
|
|
843
895
|
<a name="accessing-sources"></a>
|
844
|
-
### Accessing the underlying enumerable
|
896
|
+
### Accessing the underlying enumerable [↑](#contents)
|
845
897
|
|
846
898
|
The underlying enumerable for a table can be retrieved by calling the `sources` getter:
|
847
899
|
|
@@ -876,7 +928,7 @@ end
|
|
876
928
|
```
|
877
929
|
|
878
930
|
<a name="transposition"></a>
|
879
|
-
### Transposing rows and columns
|
931
|
+
### Transposing rows and columns [↑](#contents)
|
880
932
|
|
881
933
|
By default, Tabulo generates a table in which each row corresponds to a _record_, i.e. an element of
|
882
934
|
the underlying enumerable, and each column to a _field_. However, there are times when one instead
|
@@ -904,10 +956,10 @@ a new table in which the rows and columns are swapped:
|
|
904
956
|
By default, a header row is added to the new table, showing the string value of the element
|
905
957
|
represented in that column. This can be configured, however, along with other aspects of
|
906
958
|
`transpose`’s behaviour. For details, see the
|
907
|
-
[documentation](https://www.rubydoc.info/gems/tabulo/2.
|
959
|
+
[documentation](https://www.rubydoc.info/gems/tabulo/2.6.0/Tabulo/Table#transpose-instance_method).
|
908
960
|
|
909
961
|
<a name="borders"></a>
|
910
|
-
### Configuring borders
|
962
|
+
### Configuring borders [↑](#contents)
|
911
963
|
|
912
964
|
You can configure the kind of border and divider characters that are used when the table is printed.
|
913
965
|
This is done using the `border` option passed to `Table.new`. The options are as follows.
|
@@ -1076,7 +1128,7 @@ Note that, by default, none of the border options includes lines drawn _between_
|
|
1076
1128
|
These are configured via a separate option: see [below](#dividers).
|
1077
1129
|
|
1078
1130
|
<a name="dividers"></a>
|
1079
|
-
### Row dividers
|
1131
|
+
### Row dividers [↑](#contents)
|
1080
1132
|
|
1081
1133
|
To add lines between rows in the table body, use the `row_divider_frequency` option when initializing
|
1082
1134
|
the table. The default value for this option is `nil`, meaning there are no dividing lines between
|
@@ -1115,7 +1167,7 @@ If you want a line before every row, pass `1` to `row_divider_frequency`. For ex
|
|
1115
1167
|
```
|
1116
1168
|
|
1117
1169
|
<a name="freezing-a-table"></a>
|
1118
|
-
### Using a table as a snapshot rather than as a dynamic view
|
1170
|
+
### Using a table as a snapshot rather than as a dynamic view [↑](#contents)
|
1119
1171
|
|
1120
1172
|
The nature of a `Tabulo::Table` is that of a dynamic view onto the underlying `sources` enumerable
|
1121
1173
|
from which it was initialized (or which was subsequently assigned to its `sources` attribute). That
|
@@ -1185,7 +1237,7 @@ rendered_table = Tabulo::Table.new(1..10, :itself, :even?, :odd?).pack.to_s
|
|
1185
1237
|
```
|
1186
1238
|
|
1187
1239
|
<a name="motivation"></a>
|
1188
|
-
## Comparison with other libraries
|
1240
|
+
## Comparison with other libraries [↑](#contents)
|
1189
1241
|
|
1190
1242
|
There are other libraries for generating plain text tables in Ruby. Popular among these are:
|
1191
1243
|
|
@@ -1270,7 +1322,7 @@ environment seems cumbersome. Moreover, it seems no longer to be maintained. At
|
|
1270
1322
|
its last commit was in March 2015.
|
1271
1323
|
|
1272
1324
|
<a name="contributing"></a>
|
1273
|
-
## Contributing
|
1325
|
+
## Contributing [↑](#contents)
|
1274
1326
|
|
1275
1327
|
Issues and pull requests are welcome on GitHub at https://github.com/matt-harvey/tabulo.
|
1276
1328
|
|
@@ -1281,20 +1333,20 @@ install dependencies.
|
|
1281
1333
|
`bundle exec rake spec` will run the test suite. For a list of other Rake tasks that are available in
|
1282
1334
|
the development environment, run `bundle exec rake -T`.
|
1283
1335
|
|
1284
|
-
## License
|
1336
|
+
## License [↑](#contents)
|
1285
1337
|
|
1286
1338
|
The gem is available as open source under the terms of the [MIT
|
1287
1339
|
License](http://opensource.org/licenses/MIT).
|
1288
1340
|
|
1289
1341
|
[Gem Version]: https://rubygems.org/gems/tabulo
|
1290
|
-
[Documentation]: http://www.rubydoc.info/gems/tabulo/2.
|
1342
|
+
[Documentation]: http://www.rubydoc.info/gems/tabulo/2.6.0
|
1291
1343
|
[Build Status]: https://travis-ci.org/matt-harvey/tabulo
|
1292
1344
|
[Coverage Status]: https://coveralls.io/r/matt-harvey/tabulo
|
1293
1345
|
[Code Climate]: https://codeclimate.com/github/matt-harvey/tabulo
|
1294
1346
|
[Awesome Ruby]: https://github.com/markets/awesome-ruby#cli-utilities
|
1295
1347
|
|
1296
1348
|
[GV img]: https://img.shields.io/gem/v/tabulo.svg
|
1297
|
-
[DC img]: https://img.shields.io/badge/documentation-v2.
|
1349
|
+
[DC img]: https://img.shields.io/badge/documentation-v2.6.0-blue.svg
|
1298
1350
|
[BS img]: https://img.shields.io/travis/matt-harvey/tabulo.svg
|
1299
1351
|
[CS img]: https://img.shields.io/coveralls/matt-harvey/tabulo.svg
|
1300
1352
|
[CC img]: https://codeclimate.com/github/matt-harvey/tabulo/badges/gpa.svg
|