tabulo 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +52 -12
- data/TODO.md +0 -1
- data/lib/tabulo/row.rb +5 -1
- data/lib/tabulo/table.rb +6 -2
- data/lib/tabulo/version.rb +1 -1
- data/tabulo.gemspec +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e5af752ebead6db9dfc76f720fe93390e1476d8
|
4
|
+
data.tar.gz: 3aaeac2dcb657193be54534bac8babbad1cb56d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1227ced88276ad18ac557b66c2bf9db675dba4b9061797c7ddf9432b14c7882eb025b6b126bfa833dd15f92bd6421e42481bed5b858f369ac8c48e811a2da544
|
7
|
+
data.tar.gz: 9f68e39a20c006414d65d0239188df0ae66eb912e9e99de51ea310636d15cf2a9b0038819bbcae39f9b26982ae5f69ddcf1e410efc13cdd2c1d91cb487fbd858
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.4.2
|
4
|
+
|
5
|
+
* Improve README.
|
6
|
+
* Fix error when printing a Table, or a Row thereof, when the Table doesn't
|
7
|
+
have any columns.
|
8
|
+
* Remove unused development dependency on yard-tomdoc.
|
9
|
+
* Write more specs.
|
10
|
+
|
3
11
|
## v0.4.1
|
4
12
|
|
5
13
|
* Update README to reflect default column width of 12.
|
data/README.md
CHANGED
@@ -40,8 +40,7 @@ Each `Tabulo::Row` is also an `Enumerable`, which provides access to the underly
|
|
40
40
|
```ruby
|
41
41
|
table.each do |row|
|
42
42
|
row.each do |cell|
|
43
|
-
# 1, 2,
|
44
|
-
puts cell.class # Fixnum
|
43
|
+
# cell => 1, 2... 2, 4... etc.
|
45
44
|
end
|
46
45
|
end
|
47
46
|
```
|
@@ -138,17 +137,29 @@ the `align_header` or `align_body` options of `add_column`, e.g.:
|
|
138
137
|
### Column width, wrapping and truncation
|
139
138
|
|
140
139
|
By default, column width is fixed at 12 characters, plus 1 character of padding on either side.
|
141
|
-
This can be
|
140
|
+
This can be adjusted on a column-by-column basis using the `width` option of `add_column`:
|
142
141
|
|
143
142
|
```ruby
|
144
|
-
table.
|
143
|
+
table = Tabulo::Table.new([1, 2]) do |t|
|
144
|
+
t.add_column(:itself, width: 6)
|
145
|
+
t.add_column(:even?, width: 9)
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
149
|
+
```
|
150
|
+
> puts table
|
151
|
+
+--------+-----------+
|
152
|
+
| itself | even? |
|
153
|
+
+--------+-----------+
|
154
|
+
| 1 | false |
|
155
|
+
| 2 | true |
|
145
156
|
```
|
146
157
|
|
147
158
|
If you want to set the default column width for all columns of the table to something other
|
148
159
|
than 12, use the `column_width` option when initializing the table:
|
149
160
|
|
150
161
|
```ruby
|
151
|
-
Tabulo::Table.new([1, 2], columns: %i(itself even?), column_width: 6)
|
162
|
+
table = Tabulo::Table.new([1, 2], columns: %i(itself even?), column_width: 6)
|
152
163
|
```
|
153
164
|
|
154
165
|
```
|
@@ -158,9 +169,9 @@ than 12, use the `column_width` option when initializing the table:
|
|
158
169
|
+--------+--------+
|
159
170
|
| 1 | false |
|
160
171
|
| 2 | true |
|
161
|
-
```
|
172
|
+
```
|
162
173
|
|
163
|
-
|
174
|
+
Widths set for individual columns always override the default column width for the table.
|
164
175
|
|
165
176
|
### Overflow handling
|
166
177
|
|
@@ -208,6 +219,40 @@ table = Tabulo::Table.new(
|
|
208
219
|
| abcdefghijkl~| 26 |
|
209
220
|
```
|
210
221
|
|
222
|
+
### Formatting cell values
|
223
|
+
|
224
|
+
While the callable passed to `add_column` determines the underyling, calculated value in each
|
225
|
+
cell of the column, there is a separate concept, of a "formatter", that determines how that value will
|
226
|
+
be visually displayed. By default, `.to_s` is called on the underlying cell value to "format"
|
227
|
+
it; however, you can format it differently by passing another callable to the `formatter` option
|
228
|
+
of `add_column`:
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
table = Tabulo::Table.new(1..3) do |t|
|
232
|
+
t.add_column("N", &:itself)
|
233
|
+
t.add_column("Reciprocal", formatter: -> (n) { "%.2f" % n }) do |n|
|
234
|
+
1.0 / n
|
235
|
+
end
|
236
|
+
end
|
237
|
+
```
|
238
|
+
|
239
|
+
```
|
240
|
+
puts table
|
241
|
+
+--------------+--------------+
|
242
|
+
| N | Reciprocal |
|
243
|
+
+--------------+--------------+
|
244
|
+
| 1 | 1.00 |
|
245
|
+
| 2 | 0.50 |
|
246
|
+
| 3 | 0.33 |
|
247
|
+
```
|
248
|
+
|
249
|
+
Note the numbers in the "Reciprocal" column in this example are still right-aligned, even though
|
250
|
+
the callable passed to `formatter` returns a String. Default cell alignment is determined by the type
|
251
|
+
of the underlying cell value, not the way it is formatted. This is usually the desired result.
|
252
|
+
|
253
|
+
Note also that the item yielded to `.each` for each cell when enumerating over a `Tabulo::Row` is
|
254
|
+
the underlying value of that cell, not its formatted value.
|
255
|
+
|
211
256
|
### Repeating headers
|
212
257
|
|
213
258
|
By default, headers are only shown once, at the top of the table (`header_frequency: :start`). If
|
@@ -274,11 +319,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
274
319
|
the tests. You can also run `bin/console` for an interactive prompt that will allow you to
|
275
320
|
experiment.
|
276
321
|
|
277
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new
|
278
|
-
version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
|
279
|
-
will create a git tag for the version, push git commits and tags, and push the `.gem` file to
|
280
|
-
[rubygems.org](https://rubygems.org).
|
281
|
-
|
282
322
|
## Contributing
|
283
323
|
|
284
324
|
Bug reports and pull requests are welcome on GitHub at https://github.com/matt-harvey/tabulo.
|
data/TODO.md
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
* Consider incorporating a linter / static analysis tool into the build.
|
4
4
|
* Raise an ArgumentError for disallowed arguments and options (this is
|
5
5
|
a library!)
|
6
|
-
* Document :formatter option in README.
|
7
6
|
* Column#initialize should have the same signature as Table#add_column.
|
8
7
|
* Handle multiline cell content (i.e. when the calculated cell value
|
9
8
|
itself contains a newline).
|
data/lib/tabulo/row.rb
CHANGED
@@ -31,7 +31,11 @@ module Tabulo
|
|
31
31
|
# any column headers that appear just above it in the {Table} (depending on where this Row is
|
32
32
|
# in the {Table} and how the {Table} was configured with respect to header frequency).
|
33
33
|
def to_s
|
34
|
-
@table.
|
34
|
+
if @table.columns.any?
|
35
|
+
@table.formatted_body_row(@source, with_header: @with_header)
|
36
|
+
else
|
37
|
+
""
|
38
|
+
end
|
35
39
|
end
|
36
40
|
|
37
41
|
# @return a Hash representation of the {Row}, with column labels acting
|
data/lib/tabulo/table.rb
CHANGED
@@ -99,7 +99,11 @@ module Tabulo
|
|
99
99
|
# @return [String] a graphical "ASCII" representation of the Table, suitable for
|
100
100
|
# display in a fixed-width font.
|
101
101
|
def to_s
|
102
|
-
|
102
|
+
if @columns.any?
|
103
|
+
join_lines(map(&:to_s))
|
104
|
+
else
|
105
|
+
""
|
106
|
+
end
|
103
107
|
end
|
104
108
|
|
105
109
|
# Calls the given block once for each {Row} in the Table, passing that {Row} as parameter.
|
@@ -179,7 +183,7 @@ module Tabulo
|
|
179
183
|
end
|
180
184
|
end
|
181
185
|
|
182
|
-
subrows = (0...cell_stacks.map(&:size).max).map do |subrow_index|
|
186
|
+
subrows = (0...cell_stacks.map(&:size).max || 1).map do |subrow_index|
|
183
187
|
cell_stacks.map.with_index do |cell_stack, column_index|
|
184
188
|
if subrow_index < cell_stack.size
|
185
189
|
cell_stack[subrow_index]
|
data/lib/tabulo/version.rb
CHANGED
data/tabulo.gemspec
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.4.
|
4
|
+
version: 0.4.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: 2017-04-
|
11
|
+
date: 2017-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: yard-tomdoc
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
97
|
description: Enumerable ASCII table
|
112
98
|
email:
|
113
99
|
- software@matthewharvey.net
|