tabulo 0.4.0 → 0.4.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 +4 -0
- data/README.md +71 -56
- data/lib/tabulo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 719b6855766058c0b5086c8d04f8e85b03532fcd
|
4
|
+
data.tar.gz: ade0250e9e1ae8d136d2863df2a21f8f1efda31e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac5a02ca95749e3efcc6209e713b6620aafd416aede395546a45dae337443f932e3f80d7de3084c3f94f8cfed780516892dd54d2a393756a030ccaf6a0eaf8fe
|
7
|
+
data.tar.gz: 446462cb31aa4547245ba05cbda0ba47260c9809f8c4de35d545080a1c0d407d99d3f016cdbf4d34f83331dec7b2526b7debb987ca464bc8b46adeee075761ec
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -18,12 +18,12 @@ end
|
|
18
18
|
|
19
19
|
```
|
20
20
|
> puts table
|
21
|
-
|
22
|
-
|
|
23
|
-
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
+--------------+--------------+
|
22
|
+
| N | Doubled |
|
23
|
+
+--------------+--------------+
|
24
|
+
| 1 | 2 |
|
25
|
+
| 2 | 4 |
|
26
|
+
| 5000000 | 10000000 |
|
27
27
|
```
|
28
28
|
|
29
29
|
A `Tabulo::Table` is an `Enumerable`, so you can process one row at a time:
|
@@ -89,17 +89,17 @@ end
|
|
89
89
|
Or equivalently:
|
90
90
|
|
91
91
|
```ruby
|
92
|
-
Tabulo::Table.new([1, 2, 5], columns: %i(itself even? odd?))
|
92
|
+
table = Tabulo::Table.new([1, 2, 5], columns: %i(itself even? odd?))
|
93
93
|
```
|
94
94
|
|
95
95
|
```
|
96
96
|
> puts table
|
97
|
-
|
98
|
-
|
|
99
|
-
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
+--------------+--------------+--------------+
|
98
|
+
| itself | even? | odd? |
|
99
|
+
+--------------+--------------+--------------+
|
100
|
+
| 1 | false | true |
|
101
|
+
| 2 | true | false |
|
102
|
+
| 5 | false | true |
|
103
103
|
```
|
104
104
|
|
105
105
|
Columns can also be initialized using a callable to which each object will be passed to determine
|
@@ -116,12 +116,12 @@ end
|
|
116
116
|
|
117
117
|
```
|
118
118
|
> puts table
|
119
|
-
|
120
|
-
|
|
121
|
-
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
+--------------+--------------+--------------+
|
120
|
+
| N | Doubled | odd? |
|
121
|
+
+--------------+--------------+--------------+
|
122
|
+
| 1 | 2 | true |
|
123
|
+
| 2 | 4 | false |
|
124
|
+
| 5 | 10 | true |
|
125
125
|
```
|
126
126
|
|
127
127
|
### Cell alignment
|
@@ -151,6 +151,15 @@ than 12, use the `column_width` option when initializing the table:
|
|
151
151
|
Tabulo::Table.new([1, 2], columns: %i(itself even?), column_width: 6)
|
152
152
|
```
|
153
153
|
|
154
|
+
```
|
155
|
+
> puts table
|
156
|
+
+--------+--------+
|
157
|
+
| itself | even? |
|
158
|
+
+--------+--------+
|
159
|
+
| 1 | false |
|
160
|
+
| 2 | true |
|
161
|
+
```
|
162
|
+
|
154
163
|
The widths set for individual columns will override the default column width for the table.
|
155
164
|
|
156
165
|
### Overflow handling
|
@@ -159,19 +168,21 @@ By default, if cell contents exceed their column width, they are wrapped for as
|
|
159
168
|
required:
|
160
169
|
|
161
170
|
```ruby
|
162
|
-
table = Tabulo::Table.new(
|
171
|
+
table = Tabulo::Table.new(
|
172
|
+
["hello", "abcdefghijklmnopqrstuvwxyz"],
|
173
|
+
columns: %i(itself length)
|
174
|
+
)
|
163
175
|
```
|
164
176
|
|
165
177
|
```
|
166
178
|
> puts table
|
167
|
-
|
168
|
-
|
|
169
|
-
|
170
|
-
| hello
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
| yz | |
|
179
|
+
+--------------+--------------+
|
180
|
+
| itself | length |
|
181
|
+
+--------------+--------------+
|
182
|
+
| hello | 5 |
|
183
|
+
| abcdefghijkl | 26 |
|
184
|
+
| mnopqrstuvwx | |
|
185
|
+
| yz | |
|
175
186
|
```
|
176
187
|
|
177
188
|
Wrapping behaviour is configured for the table as a whole using the `wrap_header_cells_to` option
|
@@ -181,16 +192,20 @@ number of rows, with content truncated from that point on. The `~` character is
|
|
181
192
|
outputted cell content to show that truncation has occurred:
|
182
193
|
|
183
194
|
```ruby
|
184
|
-
table = Tabulo::Table.new(
|
195
|
+
table = Tabulo::Table.new(
|
196
|
+
["hello", "abcdefghijklmnopqrstuvwxyz"],
|
197
|
+
wrap_body_cells_to: 1,
|
198
|
+
columns: %i(itself length)
|
199
|
+
)
|
185
200
|
```
|
186
201
|
|
187
202
|
```
|
188
203
|
> puts table
|
189
|
-
|
190
|
-
|
|
191
|
-
|
192
|
-
| hello
|
193
|
-
|
|
204
|
+
+--------------+--------------+
|
205
|
+
| itself | length |
|
206
|
+
+--------------+--------------+
|
207
|
+
| hello | 5 |
|
208
|
+
| abcdefghijkl~| 26 |
|
194
209
|
```
|
195
210
|
|
196
211
|
### Repeating headers
|
@@ -208,22 +223,22 @@ table = Tabulo::Table.new(1..10, columns: %i(itself even?), header_frequency: 5)
|
|
208
223
|
|
209
224
|
```
|
210
225
|
> puts table
|
211
|
-
|
212
|
-
|
|
213
|
-
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
220
|
-
|
|
221
|
-
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
226
|
+
+--------------+--------------+
|
227
|
+
| itself | even? |
|
228
|
+
+--------------+--------------+
|
229
|
+
| 1 | false |
|
230
|
+
| 2 | true |
|
231
|
+
| 3 | false |
|
232
|
+
| 4 | true |
|
233
|
+
| 5 | false |
|
234
|
+
+--------------+--------------+
|
235
|
+
| itself | even? |
|
236
|
+
+--------------+--------------+
|
237
|
+
| 6 | true |
|
238
|
+
| 7 | false |
|
239
|
+
| 8 | true |
|
240
|
+
| 9 | false |
|
241
|
+
| 10 | true |
|
227
242
|
```
|
228
243
|
|
229
244
|
### Using a Table Enumerator
|
@@ -235,17 +250,17 @@ for example, you might do this:
|
|
235
250
|
```
|
236
251
|
> e = Tabulo::Table.new(User.find_each) do |t|
|
237
252
|
t.add_column(:id)
|
238
|
-
t.add_column(:email, width:
|
253
|
+
t.add_column(:email, width: 24)
|
239
254
|
end.to_enum # <-- make an Enumerator
|
240
255
|
...
|
241
256
|
> puts e.next
|
242
|
-
|
243
|
-
|
|
244
|
-
|
245
|
-
|
|
257
|
+
+--------------+--------------------------+
|
258
|
+
| id | email |
|
259
|
+
+--------------+--------------------------+
|
260
|
+
| 1 | jane@example.com |
|
246
261
|
=> nil
|
247
262
|
> puts e.next
|
248
|
-
|
|
263
|
+
| 2 | betty@example.net |
|
249
264
|
=> nil
|
250
265
|
```
|
251
266
|
|
data/lib/tabulo/version.rb
CHANGED