tabulo 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ackrc +10 -0
- data/.rdoc_options +0 -1
- data/CHANGELOG.md +7 -0
- data/README.md +10 -1
- data/TODO.md +0 -1
- data/lib/tabulo/column.rb +1 -1
- data/lib/tabulo/table.rb +16 -17
- data/lib/tabulo/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ee932d2d03998f4b0e537e8d5302887660326e4
|
4
|
+
data.tar.gz: 3884ac4f5a066f67819423fd7ca0c86437b7e690
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23ea187faca64ed1343c42d82db8858bdda1ee219a53e93f6a1d2cb1dc14805d729cc5503e989df30f637ecb10807c59f051d7b48e8bc85527b9035b4b75beba
|
7
|
+
data.tar.gz: 5170b8b8761296d4cb05d620bf98d9871a94ea32938b32945b98dc72b8f64f3d4fe9bed6df7444727364d0658816abf94e3b21e92065d9a140e9cbbca60e8774
|
data/.ackrc
ADDED
data/.rdoc_options
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.4.0
|
4
|
+
|
5
|
+
* Increase default column width from 8 to 12
|
6
|
+
* Allow default column width to be configured when initializing a Table
|
7
|
+
* Minor code tidy-ups, including removal of undocumented ability for
|
8
|
+
Table#add_column to accept a Column instance directly.
|
9
|
+
|
3
10
|
## v0.3.1
|
4
11
|
|
5
12
|
* Fix width and other options ignored by Table#add_column.
|
data/README.md
CHANGED
@@ -137,13 +137,22 @@ the `align_header` or `align_body` options of `add_column`, e.g.:
|
|
137
137
|
|
138
138
|
### Column width, wrapping and truncation
|
139
139
|
|
140
|
-
By default, column width is fixed at
|
140
|
+
By default, column width is fixed at 12 characters, plus 1 character of padding on either side.
|
141
141
|
This can be customized using the `width` option of `add_column`:
|
142
142
|
|
143
143
|
```ruby
|
144
144
|
table.add_column(:even?, width: 5)
|
145
145
|
```
|
146
146
|
|
147
|
+
If you want to set the default column width for all columns of the table to something other
|
148
|
+
than 12, use the `column_width` option when initializing the table:
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
Tabulo::Table.new([1, 2], columns: %i(itself even?), column_width: 6)
|
152
|
+
```
|
153
|
+
|
154
|
+
The widths set for individual columns will override the default column width for the table.
|
155
|
+
|
147
156
|
### Overflow handling
|
148
157
|
|
149
158
|
By default, if cell contents exceed their column width, they are wrapped for as many rows as
|
data/TODO.md
CHANGED
@@ -4,7 +4,6 @@
|
|
4
4
|
* Raise an ArgumentError for disallowed arguments and options (this is
|
5
5
|
a library!)
|
6
6
|
* Document :formatter option in README.
|
7
|
-
* Allow default column width to be configured at level of Table.
|
8
7
|
* Column#initialize should have the same signature as Table#add_column.
|
9
8
|
* Handle multiline cell content (i.e. when the calculated cell value
|
10
9
|
itself contains a newline).
|
data/lib/tabulo/column.rb
CHANGED
@@ -12,7 +12,7 @@ module Tabulo
|
|
12
12
|
@align_body = options[:align_body] || nil
|
13
13
|
@extractor = options[:extractor] || @label.to_proc
|
14
14
|
@formatter = options[:formatter] || :to_s.to_proc
|
15
|
-
@width = options[:width]
|
15
|
+
@width = options[:width]
|
16
16
|
end
|
17
17
|
|
18
18
|
# @!visibility private
|
data/lib/tabulo/table.rb
CHANGED
@@ -6,7 +6,7 @@ module Tabulo
|
|
6
6
|
class Table
|
7
7
|
include Enumerable
|
8
8
|
|
9
|
-
DEFAULT_COLUMN_WIDTH =
|
9
|
+
DEFAULT_COLUMN_WIDTH = 12
|
10
10
|
|
11
11
|
HORIZONTAL_RULE_CHARACTER = "-"
|
12
12
|
CORNER_CHARACTER = "+"
|
@@ -20,6 +20,8 @@ module Tabulo
|
|
20
20
|
# Each element of the Array will be used to create a column whose content is
|
21
21
|
# created by calling the corresponding method on each element of sources. Note
|
22
22
|
# the {#add_column} method is a much more flexible way to set up columns on the table.
|
23
|
+
# @option options [Fixnum, nil] :column_width (nil) The default column width for columns in this
|
24
|
+
# table, not excluding padding. If nil, then DEFAULT_COLUMN_WIDTH will be used.
|
23
25
|
# @option options [:start, nil, Fixnum] :header_frequency (:start) Controls the display of column headers.
|
24
26
|
# If passed <tt>:start</tt>, headers will be shown at the top of the table only. If passed <tt>nil</tt>,
|
25
27
|
# headers will not be shown. If passed a Fixnum N (> 0), headers will be shown at the top of the table,
|
@@ -37,6 +39,7 @@ module Tabulo
|
|
37
39
|
def initialize(sources, options = { })
|
38
40
|
opts = {
|
39
41
|
columns: [],
|
42
|
+
column_width: DEFAULT_COLUMN_WIDTH,
|
40
43
|
header_frequency: :start,
|
41
44
|
|
42
45
|
# nil to wrap to no max, 1 to wrap to 1 row then truncate, etc..
|
@@ -52,7 +55,7 @@ module Tabulo
|
|
52
55
|
@joiner = "|"
|
53
56
|
@truncation_indicator = "~"
|
54
57
|
@padding_character = " "
|
55
|
-
@default_column_width = DEFAULT_COLUMN_WIDTH
|
58
|
+
@default_column_width = opts[:column_width] || DEFAULT_COLUMN_WIDTH
|
56
59
|
@columns = opts[:columns].map { |item| make_column(item) }
|
57
60
|
yield self if block_given?
|
58
61
|
end
|
@@ -75,8 +78,9 @@ module Tabulo
|
|
75
78
|
# by the type of the cell value, with numbers aligned right, booleans center-aligned, and
|
76
79
|
# other values left-aligned. Note header text alignment is configured separately using the
|
77
80
|
# :align_header option.
|
78
|
-
# @option options [Fixnum] :width (
|
79
|
-
#
|
81
|
+
# @option options [Fixnum] :width (nil) Specifies the width of the column, excluding padding. If
|
82
|
+
# nil, then the column will take the width provided by the `column_width` option
|
83
|
+
# with which the Table was initialized.
|
80
84
|
# @option options [#to_proc] :formatter (:to_s.to_proc) A lambda or other callable object that
|
81
85
|
# will be passed the calculated value of each cell to determine how it should be displayed. This
|
82
86
|
# is distinct from the extractor (see below). For example, if the extractor for this column
|
@@ -195,19 +199,14 @@ module Tabulo
|
|
195
199
|
|
196
200
|
# @!visibility private
|
197
201
|
def make_column(item, options = { })
|
198
|
-
|
199
|
-
|
200
|
-
item
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
width: @default_column_width,
|
207
|
-
formatter: :to_s.to_proc
|
208
|
-
|
209
|
-
}.merge(options))
|
210
|
-
end
|
202
|
+
Column.new({
|
203
|
+
label: item.to_sym,
|
204
|
+
header: item.to_s,
|
205
|
+
align_header: :center,
|
206
|
+
width: @default_column_width,
|
207
|
+
formatter: :to_s.to_proc
|
208
|
+
|
209
|
+
}.merge(options))
|
211
210
|
end
|
212
211
|
end
|
213
212
|
end
|
data/lib/tabulo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabulo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Harvey
|
@@ -115,6 +115,7 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
+
- ".ackrc"
|
118
119
|
- ".gitignore"
|
119
120
|
- ".rdoc_options"
|
120
121
|
- ".rspec"
|