tabulo 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33261a1329d456e8dd354fe214a9d437c718be38
4
- data.tar.gz: 209b8bc48027f4f999892e9d9e843cdef657c48a
3
+ metadata.gz: 5b182912c5f405049dd0098da2154e460ac625bb
4
+ data.tar.gz: 7cbae37e2ce3779cd6ff70803392cdb21aae1358
5
5
  SHA512:
6
- metadata.gz: 6052a5c65b3429cd89075fa5b4b646166dde567724d983bd96eb8fab4fdfcdf6abde7a683ed29b67d19667374d757de5a207f7a1432f02116a690cdd68acbe8f
7
- data.tar.gz: 0e5794904aa0d3ffc53239a5167b477c5695532eed749f59b11437e20f16e6693126a53dd7fc181dcb372f3997dfdd128311e199d3a444e13b6468249523fa16
6
+ metadata.gz: 929a1aa6ad4a46837e0d916dd67bfd6d01b664d214f9533bcf2d8c82da4509d17e2f220b02d9353f95d558e07e9908b62e97f18dbb86440242a8f1c36c89d587
7
+ data.tar.gz: 449cea43dd183067878f3417729c18144dfd7a8e2016048b68b197e6d4bf936dfbf5a558e2e68453924fc6cadc9818e5388c2392474a5d91a26a933af7ea5d44
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### v1.2.0
4
+
5
+ * Allow customization of padding.
6
+
3
7
  ### v1.1.0
4
8
 
5
9
  * Allow customization of horizontal divider, vertical divider and intersection characters.
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![Gem Version][GV img]][Gem Version]
4
4
  [![Coverage Status][CS img]][Coverage Status]
5
5
  [![Build Status][BS img]][Build Status]
6
- [![Documentation][DC img]][Documentation]
7
6
 
8
7
  ## Overview
9
8
 
@@ -173,6 +172,10 @@ table = Tabulo::Table.new([1, 2], columns: %i[itself even?], column_width: 6)
173
172
 
174
173
  Widths set for individual columns always override the default column width for the table.
175
174
 
175
+ Note the single character of padding either side of each column is not counted in the column width.
176
+ The amount of this padding can be configured for the table as a whole, using the `column_padding`
177
+ option passed to `Table.new`.
178
+
176
179
  <a name="shrinkwrap"></a>
177
180
  #### Automating column widths
178
181
 
@@ -375,6 +378,15 @@ underlying collection. (This is negated if we [shrinkwrap](#shrinkwrap) the tabl
375
378
  in that case the entire collection must be traversed up front in order for column widths to be
376
379
  calculated.)
377
380
 
381
+ ### Additional configuration options
382
+
383
+ The characters used for horizontal dividers, vertical dividers and corners, which default to `-`,
384
+ `|` and `+` respectively, can be configured using the using the `horizontal_rule_character`,
385
+ `vertical_rule_character` and `intersection_character` options passed to `Table.new`.
386
+
387
+ The character used to indicate truncation, which defaults to `~`, can be configured using the
388
+ `truncation_indicator` option passed to `Table.new`.
389
+
378
390
  ## Development
379
391
 
380
392
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run
@@ -393,9 +405,7 @@ License](http://opensource.org/licenses/MIT).
393
405
  [Gem Version]: https://rubygems.org/gems/tabulo
394
406
  [Build Status]: https://travis-ci.org/matt-harvey/tabulo
395
407
  [Coverage Status]: https://coveralls.io/r/matt-harvey/tabulo
396
- [Documentation]: http://www.rubydoc.info/gems/tabulo/1.1.0
397
408
 
398
409
  [GV img]: https://img.shields.io/gem/v/tabulo.svg?style=plastic
399
410
  [BS img]: https://img.shields.io/travis/matt-harvey/tabulo.svg?style=plastic
400
411
  [CS img]: https://img.shields.io/coveralls/matt-harvey/tabulo.svg?style=plastic
401
- [DC img]: https://img.shields.io/badge/docs-v1.1.0-blue.svg?style=plastic
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -9,6 +9,9 @@ module Tabulo
9
9
  # @!visibility public
10
10
  DEFAULT_COLUMN_WIDTH = 12
11
11
 
12
+ # @!visibility public
13
+ DEFAULT_COLUMN_PADDING = 1
14
+
12
15
  # @!visibility public
13
16
  DEFAULT_HORIZONTAL_RULE_CHARACTER = "-"
14
17
 
@@ -65,11 +68,13 @@ module Tabulo
65
68
  # cell's content has been truncated. If omitted or passed <tt>nil</tt>,
66
69
  # defaults to {DEFAULT_TRUNCATION_INDICATOR}. If passed something other than <tt>nil</tt> or
67
70
  # a single-character String, raises {InvalidTruncationIndicatorError}.
71
+ # @param [nil, Integer] column_padding Determines the amount of blank space with which to pad either
72
+ # of each column. Defaults to 1.
68
73
  # @return [Table] a new Table
69
74
  # @raise [InvalidColumnLabelError] if non-unique Symbols are provided to columns.
70
75
  # @raise [InvalidHorizontalRuleCharacterError] if invalid argument passed to horizontal_rule_character.
71
76
  # @raise [InvalidVerticalRuleCharacterError] if invalid argument passed to vertical_rule_character.
72
- def initialize(sources, columns: [], column_width: nil, header_frequency: :start,
77
+ def initialize(sources, columns: [], column_width: nil, column_padding: nil, header_frequency: :start,
73
78
  wrap_header_cells_to: nil, wrap_body_cells_to: nil, horizontal_rule_character: nil,
74
79
  vertical_rule_character: nil, intersection_character: nil, truncation_indicator: nil)
75
80
 
@@ -78,6 +83,7 @@ module Tabulo
78
83
  @wrap_header_cells_to = wrap_header_cells_to
79
84
  @wrap_body_cells_to = wrap_body_cells_to
80
85
  @default_column_width = (column_width || DEFAULT_COLUMN_WIDTH)
86
+ @column_padding = (column_padding || DEFAULT_COLUMN_PADDING)
81
87
 
82
88
  @horizontal_rule_character = validate_character(horizontal_rule_character,
83
89
  DEFAULT_HORIZONTAL_RULE_CHARACTER, InvalidHorizontalRuleCharacterError, "horizontal rule character")
@@ -196,7 +202,7 @@ module Tabulo
196
202
  #
197
203
  def horizontal_rule
198
204
  inner = column_registry.map do |_, column|
199
- @horizontal_rule_character * (column.width + 2)
205
+ @horizontal_rule_character * (column.width + @column_padding * 2)
200
206
  end
201
207
  surround_join(inner, @intersection_character)
202
208
  end
@@ -244,7 +250,7 @@ module Tabulo
244
250
 
245
251
  if max_table_width
246
252
  total_columns_width = columns.inject(0) { |sum, column| sum + column.width }
247
- total_padding = column_registry.count * 2
253
+ total_padding = column_registry.count * @column_padding * 2
248
254
  total_borders = column_registry.count + 1
249
255
  unadjusted_table_width = total_columns_width + total_padding + total_borders
250
256
 
@@ -307,8 +313,13 @@ module Tabulo
307
313
  cell_truncated = (num_subcells > row_height)
308
314
  append_truncator = (cell_truncated && subrow_index + 1 == row_height)
309
315
 
310
- lpad = PADDING_CHARACTER
311
- rpad = (append_truncator ? @truncation_indicator : PADDING_CHARACTER)
316
+ lpad = PADDING_CHARACTER * @column_padding
317
+ rpad =
318
+ if append_truncator && @column_padding != 0
319
+ @truncation_indicator + PADDING_CHARACTER * (@column_padding - 1)
320
+ else
321
+ PADDING_CHARACTER * @column_padding
322
+ end
312
323
 
313
324
  inner =
314
325
  if subrow_index < num_subcells
@@ -1,3 +1,3 @@
1
1
  module Tabulo
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
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: 1.1.0
4
+ version: 1.2.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: 2018-07-14 00:00:00.000000000 Z
11
+ date: 2018-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler