tabulo 0.6.3 → 1.0.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 +1 -1
- data/CHANGELOG.md +5 -0
- data/README.md +10 -10
- data/VERSION +1 -1
- data/_config.yml +1 -0
- data/lib/tabulo/row.rb +1 -1
- data/lib/tabulo/table.rb +19 -16
- data/lib/tabulo/version.rb +1 -1
- data/tabulo.gemspec +2 -2
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a910d751c5f088a4cd7c5fbae68747885c15038
|
4
|
+
data.tar.gz: b5c7538803ec163bbad593eec5f45604fc58fb0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1362c34d1d078488ced0b4f7cefc0fb697eb7b8de6602e27a3a406efb65f81a955bdf17f6f075a9df998b4b5db771e1b3c6e57781773dc9c06033fba9d1bf4c
|
7
|
+
data.tar.gz: bdb51c2747da845b04dfac1bf49f4c3320f1dc1eacd306a4d96596fca17a54738dab88714771dca96a0d1158a57fc21e66c07fbae09f7d6299c6045b9cd226b1
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -86,7 +86,7 @@ end
|
|
86
86
|
Or equivalently:
|
87
87
|
|
88
88
|
```ruby
|
89
|
-
table = Tabulo::Table.new([1, 2, 5], columns: %i
|
89
|
+
table = Tabulo::Table.new([1, 2, 5], columns: %i[itself even? odd?])
|
90
90
|
```
|
91
91
|
|
92
92
|
```
|
@@ -161,7 +161,7 @@ If you want to set the default column width for all columns of the table to some
|
|
161
161
|
than 12, use the `column_width` option when initializing the table:
|
162
162
|
|
163
163
|
```ruby
|
164
|
-
table = Tabulo::Table.new([1, 2], columns: %i
|
164
|
+
table = Tabulo::Table.new([1, 2], columns: %i[itself even?], column_width: 6)
|
165
165
|
```
|
166
166
|
|
167
167
|
```
|
@@ -183,7 +183,7 @@ itself, so that each column is just wide enough for its header and contents (plu
|
|
183
183
|
of padding):
|
184
184
|
|
185
185
|
```ruby
|
186
|
-
table = Tabulo::Table.new([1, 2], columns: %i
|
186
|
+
table = Tabulo::Table.new([1, 2], columns: %i[itself even?])
|
187
187
|
table.shrinkwrap!
|
188
188
|
```
|
189
189
|
|
@@ -199,14 +199,14 @@ table.shrinkwrap!
|
|
199
199
|
The `shrinkwrap!` method returns the table itself, so you can "wrap-and-print" in one go:
|
200
200
|
|
201
201
|
```ruby
|
202
|
-
puts Tabulo::Table.new([1, 2], columns: %i
|
202
|
+
puts Tabulo::Table.new([1, 2], columns: %i[itself even?]).shrinkwrap!
|
203
203
|
```
|
204
204
|
|
205
205
|
<a name="max-table-width"></a>
|
206
206
|
You can place an upper limit on the total width of the table when shrinkwrapping:
|
207
207
|
|
208
208
|
```ruby
|
209
|
-
puts Tabulo::Table.new([1, 2], columns: %i
|
209
|
+
puts Tabulo::Table.new([1, 2], columns: %i[itself even?]).shrinkwrap!(max_table_width: 17)
|
210
210
|
```
|
211
211
|
|
212
212
|
```
|
@@ -242,7 +242,7 @@ required:
|
|
242
242
|
```ruby
|
243
243
|
table = Tabulo::Table.new(
|
244
244
|
["hello", "abcdefghijklmnopqrstuvwxyz"],
|
245
|
-
columns: %i
|
245
|
+
columns: %i[itself length]
|
246
246
|
)
|
247
247
|
```
|
248
248
|
|
@@ -267,7 +267,7 @@ outputted cell content to show that truncation has occurred:
|
|
267
267
|
table = Tabulo::Table.new(
|
268
268
|
["hello", "abcdefghijklmnopqrstuvwxyz"],
|
269
269
|
wrap_body_cells_to: 1,
|
270
|
-
columns: %i
|
270
|
+
columns: %i[itself length]
|
271
271
|
)
|
272
272
|
```
|
273
273
|
|
@@ -325,7 +325,7 @@ at table that's taller than your terminal.
|
|
325
325
|
E.g.:
|
326
326
|
|
327
327
|
```ruby
|
328
|
-
table = Tabulo::Table.new(1..10, columns: %i
|
328
|
+
table = Tabulo::Table.new(1..10, columns: %i[itself even?], header_frequency: 5)
|
329
329
|
```
|
330
330
|
|
331
331
|
```
|
@@ -397,11 +397,11 @@ License](http://opensource.org/licenses/MIT).
|
|
397
397
|
[Dependency Status]: https://gemnasium.com/matt-harvey/tabulo
|
398
398
|
[Coverage Status]: https://coveralls.io/r/matt-harvey/tabulo
|
399
399
|
[Code Climate]: https://codeclimate.com/github/matt-harvey/tabulo
|
400
|
-
[Documentation]: http://www.rubydoc.info/
|
400
|
+
[Documentation]: http://www.rubydoc.info/gems/tabulo/1.0.0
|
401
401
|
|
402
402
|
[GV img]: https://img.shields.io/gem/v/tabulo.svg?style=plastic
|
403
403
|
[BS img]: https://img.shields.io/travis/matt-harvey/tabulo.svg?style=plastic
|
404
404
|
[DS img]: https://img.shields.io/gemnasium/matt-harvey/tabulo.svg?style=plastic
|
405
405
|
[CS img]: https://img.shields.io/coveralls/matt-harvey/tabulo.svg?style=plastic
|
406
406
|
[CC img]: https://img.shields.io/codeclimate/github/matt-harvey/tabulo.svg?style=plastic
|
407
|
-
[DC img]: https://img.shields.io/badge/docs-
|
407
|
+
[DC img]: https://img.shields.io/badge/docs-v1.0.0-blue.svg?style=plastic
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-cayman
|
data/lib/tabulo/row.rb
CHANGED
data/lib/tabulo/table.rb
CHANGED
@@ -152,7 +152,7 @@ module Tabulo
|
|
152
152
|
|
153
153
|
# @return [String] an "ASCII" graphical representation of the Table column headers.
|
154
154
|
def formatted_header
|
155
|
-
cells = column_registry.map { |
|
155
|
+
cells = column_registry.map { |_, column| column.header_subcells }
|
156
156
|
format_row(cells, @wrap_header_cells_to)
|
157
157
|
end
|
158
158
|
|
@@ -165,7 +165,7 @@ module Tabulo
|
|
165
165
|
# end
|
166
166
|
#
|
167
167
|
def horizontal_rule
|
168
|
-
inner = column_registry.map do |
|
168
|
+
inner = column_registry.map do |_, column|
|
169
169
|
surround(column.horizontal_rule, HORIZONTAL_RULE_CHARACTER)
|
170
170
|
end
|
171
171
|
surround_join(inner, CORNER_CHARACTER)
|
@@ -199,25 +199,21 @@ module Tabulo
|
|
199
199
|
# @return [Table] the Table itself
|
200
200
|
def shrinkwrap!(max_table_width: nil)
|
201
201
|
return self if column_registry.none?
|
202
|
+
columns = column_registry.values
|
202
203
|
|
203
|
-
|
204
|
-
|
205
|
-
column_registry.each do |label, column|
|
206
|
-
column.width = wrapped_width.call(column.header)
|
204
|
+
columns.each do |column|
|
205
|
+
column.width = wrapped_width(column.header)
|
207
206
|
end
|
208
207
|
|
209
208
|
@sources.each do |source|
|
210
|
-
|
211
|
-
width = wrapped_width
|
209
|
+
columns.each do |column|
|
210
|
+
width = wrapped_width(column.formatted_cell_content(source))
|
212
211
|
column.width = width if width > column.width
|
213
212
|
end
|
214
213
|
end
|
215
214
|
|
216
215
|
if max_table_width
|
217
|
-
total_columns_width =
|
218
|
-
_label, column = label_with_column
|
219
|
-
sum + column.width
|
220
|
-
end
|
216
|
+
total_columns_width = columns.inject(0) { |sum, column| sum + column.width }
|
221
217
|
total_padding = column_registry.count * 2
|
222
218
|
total_borders = column_registry.count + 1
|
223
219
|
unadjusted_table_width = total_columns_width + total_padding + total_borders
|
@@ -230,9 +226,7 @@ module Tabulo
|
|
230
226
|
required_reduction = [unadjusted_table_width - max_table_width, 0].max
|
231
227
|
|
232
228
|
required_reduction.times do
|
233
|
-
|
234
|
-
widest_column = column_registry.inject(first_column) do |widest, label_with_column|
|
235
|
-
_label, column = label_with_column
|
229
|
+
widest_column = columns.inject(columns.first) do |widest, column|
|
236
230
|
column.width >= widest.width ? column : widest
|
237
231
|
end
|
238
232
|
|
@@ -245,7 +239,7 @@ module Tabulo
|
|
245
239
|
|
246
240
|
# @!visibility private
|
247
241
|
def formatted_body_row(source, with_header: false)
|
248
|
-
cells = column_registry.map { |
|
242
|
+
cells = column_registry.map { |_, column| column.body_subcells(source) }
|
249
243
|
inner = format_row(cells, @wrap_body_cells_to)
|
250
244
|
if with_header
|
251
245
|
join_lines([horizontal_rule, formatted_header, horizontal_rule, inner])
|
@@ -316,5 +310,14 @@ module Tabulo
|
|
316
310
|
def join_lines(lines)
|
317
311
|
lines.join($/) # join strings with cross-platform newline
|
318
312
|
end
|
313
|
+
|
314
|
+
# @!visibility private
|
315
|
+
# @return [Fixnum] the length of the longest segment of str when split by newlines
|
316
|
+
def wrapped_width(str)
|
317
|
+
segments = str.split($/)
|
318
|
+
segments.inject(1) do |length, segment|
|
319
|
+
length > segment.length ? length : segment.length
|
320
|
+
end
|
321
|
+
end
|
319
322
|
end
|
320
323
|
end
|
data/lib/tabulo/version.rb
CHANGED
data/tabulo.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = "Enumerable ASCII table"
|
13
13
|
spec.description = "Enumerable ASCII table"
|
14
|
-
spec.homepage = "https://
|
14
|
+
spec.homepage = "https://matt-harvey.github.io/tabulo"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.required_ruby_version = ">= 2.1.10"
|
25
25
|
|
26
|
-
spec.add_development_dependency "bundler", "~> 1.
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.15.1"
|
27
27
|
spec.add_development_dependency "rake", "~> 11.0"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
29
|
spec.add_development_dependency "simplecov"
|
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
|
+
version: 1.0.0
|
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-
|
11
|
+
date: 2017-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.15.1
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.15.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- README.md
|
156
156
|
- Rakefile
|
157
157
|
- VERSION
|
158
|
+
- _config.yml
|
158
159
|
- bin/console
|
159
160
|
- bin/setup
|
160
161
|
- lib/tabulo.rb
|
@@ -164,7 +165,7 @@ files:
|
|
164
165
|
- lib/tabulo/table.rb
|
165
166
|
- lib/tabulo/version.rb
|
166
167
|
- tabulo.gemspec
|
167
|
-
homepage: https://
|
168
|
+
homepage: https://matt-harvey.github.io/tabulo
|
168
169
|
licenses:
|
169
170
|
- MIT
|
170
171
|
metadata: {}
|