tabulo 1.0.1 → 1.1.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: fb96e6f0dd6059d898a0bce0d60b8d97cc3c08fc
4
- data.tar.gz: 84e67bf09c8e7058789bacecaabace6c1b0fa4af
3
+ metadata.gz: 33261a1329d456e8dd354fe214a9d437c718be38
4
+ data.tar.gz: 209b8bc48027f4f999892e9d9e843cdef657c48a
5
5
  SHA512:
6
- metadata.gz: 2eff9dc5e7a946ea6b0ed95e5ddff7f987c39c8308ed3199447c8c0f1ad21f1f1d4ff4af7ffe0df35cf6167d2729f4c5f4ba04b62d28e37516ea71e6bee8fc3a
7
- data.tar.gz: 1ca3aeeba0dd8333ca398b1245dea596e93d0b4cd11cb4f013a56d2f7dbb9d9aaba330829e16ad1b1c77419c6b1862a7da71be0082f758ff27fc4b41e1804b2f
6
+ metadata.gz: 6052a5c65b3429cd89075fa5b4b646166dde567724d983bd96eb8fab4fdfcdf6abde7a683ed29b67d19667374d757de5a207f7a1432f02116a690cdd68acbe8f
7
+ data.tar.gz: 0e5794904aa0d3ffc53239a5167b477c5695532eed749f59b11437e20f16e6693126a53dd7fc181dcb372f3997dfdd128311e199d3a444e13b6468249523fa16
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### v1.1.0
4
+
5
+ * Allow customization of horizontal divider, vertical divider and intersection characters.
6
+
3
7
  ### v1.0.1
4
8
 
5
9
  * Fix deprecation warnings.
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Tabulo
2
2
 
3
3
  [![Gem Version][GV img]][Gem Version]
4
- [![Dependency Status][DS img]][Dependency Status]
5
4
  [![Coverage Status][CS img]][Coverage Status]
6
5
  [![Build Status][BS img]][Build Status]
7
6
  [![Documentation][DC img]][Documentation]
@@ -393,12 +392,10 @@ License](http://opensource.org/licenses/MIT).
393
392
 
394
393
  [Gem Version]: https://rubygems.org/gems/tabulo
395
394
  [Build Status]: https://travis-ci.org/matt-harvey/tabulo
396
- [Dependency Status]: https://gemnasium.com/matt-harvey/tabulo
397
395
  [Coverage Status]: https://coveralls.io/r/matt-harvey/tabulo
398
- [Documentation]: http://www.rubydoc.info/gems/tabulo/1.0.1
396
+ [Documentation]: http://www.rubydoc.info/gems/tabulo/1.1.0
399
397
 
400
398
  [GV img]: https://img.shields.io/gem/v/tabulo.svg?style=plastic
401
399
  [BS img]: https://img.shields.io/travis/matt-harvey/tabulo.svg?style=plastic
402
- [DS img]: https://img.shields.io/gemnasium/matt-harvey/tabulo.svg?style=plastic
403
400
  [CS img]: https://img.shields.io/coveralls/matt-harvey/tabulo.svg?style=plastic
404
- [DC img]: https://img.shields.io/badge/docs-v1.0.1-blue.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.0.1
1
+ 1.1.0
@@ -7,7 +7,6 @@ module Tabulo
7
7
  attr_reader :header
8
8
 
9
9
  def initialize(header:, width:, align_header:, align_body:, formatter:, extractor:)
10
-
11
10
  @header = header
12
11
  @width = width
13
12
  @align_header = align_header
@@ -20,10 +19,6 @@ module Tabulo
20
19
  infilled_subcells(@header, @align_header)
21
20
  end
22
21
 
23
- def horizontal_rule
24
- Table::HORIZONTAL_RULE_CHARACTER * width
25
- end
26
-
27
22
  def body_subcells(source)
28
23
  cell_datum = body_cell_value(source)
29
24
  formatted_content = @formatter.call(cell_datum)
@@ -2,4 +2,20 @@ module Tabulo
2
2
 
3
3
  # Error indicating that the label of a column is invalid.
4
4
  class InvalidColumnLabelError < StandardError; end
5
+
6
+ # Error indicating that an attempt was made to use an invalid horizontal rule character
7
+ # for the table.
8
+ class InvalidHorizontalRuleCharacterError < StandardError; end
9
+
10
+ # Error indicating that an attempt was made to use an invalid vertical rule character
11
+ # for the table.
12
+ class InvalidVerticalRuleCharacterError < StandardError; end
13
+
14
+ # Error indicating that an attempt was made to use an invalid intersection character for
15
+ # the table.
16
+ class InvalidIntersectionCharacterError < StandardError; end
17
+
18
+ # Error indicating that an attempt was made to use an invalid truncation indicator for
19
+ # the table.
20
+ class InvalidTruncationIndicatorError < StandardError; end
5
21
  end
@@ -6,23 +6,23 @@ module Tabulo
6
6
  class Table
7
7
  include Enumerable
8
8
 
9
- # @!visibility private
9
+ # @!visibility public
10
10
  DEFAULT_COLUMN_WIDTH = 12
11
11
 
12
- # @!visibility private
13
- HORIZONTAL_RULE_CHARACTER = "-"
12
+ # @!visibility public
13
+ DEFAULT_HORIZONTAL_RULE_CHARACTER = "-"
14
14
 
15
- # @!visibility private
16
- VERTICAL_RULE_CHARACTER = "|"
15
+ # @!visibility public
16
+ DEFAULT_VERTICAL_RULE_CHARACTER = "|"
17
17
 
18
- # @!visibility private
19
- CORNER_CHARACTER = "+"
18
+ # @!visibility public
19
+ DEFAULT_INTERSECTION_CHARACTER = "+"
20
20
 
21
- # @!visibility private
22
- PADDING_CHARACTER = " "
21
+ # @!visibility public
22
+ DEFAULT_TRUNCATION_INDICATOR = "~"
23
23
 
24
24
  # @!visibility private
25
- TRUNCATION_INDICATOR = "~"
25
+ PADDING_CHARACTER = " "
26
26
 
27
27
  # @!visibility private
28
28
  attr_reader :column_registry
@@ -33,7 +33,7 @@ module Tabulo
33
33
  # created by calling the corresponding method on each element of sources. Note
34
34
  # the {#add_column} method is a much more flexible way to set up columns on the table.
35
35
  # @param [Integer, nil] column_width The default column width for columns in this
36
- # table, not excluding padding. If nil, then DEFAULT_COLUMN_WIDTH will be used.
36
+ # table, not excluding padding. If <tt>nil</tt>, then {DEFAULT_COLUMN_WIDTH} will be used.
37
37
  # @param [:start, nil, Integer] header_frequency Controls the display of column headers.
38
38
  # If passed <tt>:start</tt>, headers will be shown at the top of the table only. If passed <tt>nil</tt>,
39
39
  # headers will not be shown. If passed an Integer N (> 0), headers will be shown at the top of the table,
@@ -46,18 +46,48 @@ module Tabulo
46
46
  # headers), if their content is longer than the column's fixed width. If passed <tt>nil</tt>, content will
47
47
  # be wrapped for as many rows as required to accommodate it. If passed an Integer N (> 0), content will be
48
48
  # wrapped up to N rows and then truncated thereafter.
49
+ # headers), if their content is longer than the column's fixed width. If passed <tt>nil</tt>, content will
50
+ # be wrapped for as many rows as required to accommodate it. If passed an Integer N (> 0), content will be
51
+ # wrapped up to N rows and then truncated thereafter.
52
+ # @param [nil, String] horizontal_rule_character Determines the character used to draw
53
+ # horizontal lines where required in the table. If omitted or passed <tt>nil</tt>, defaults to
54
+ # {DEFAULT_HORIZONTAL_RULE_CHARACTER}. If passed something other than <tt>nil</tt> or a single-character
55
+ # String, raises {InvalidHorizontalRuleCharacterError}.
56
+ # @param [nil, String] vertical_rule_character Determines the character used to draw
57
+ # vertical lines where required in the table. If omitted or passed <tt>nil</tt>, defaults to
58
+ # {DEFAULT_VERTICAL_RULE_CHARACTER}. If passed something other than <tt>nil</tt> or a single-character
59
+ # String, raises {InvalidVerticalRuleCharacterError}.
60
+ # @param [nil, String] intersection_character Determines the character used to draw
61
+ # line intersections and corners where required in the table. If omitted or passed <tt>nil</tt>,
62
+ # defaults to {DEFAULT_INTERSECTION_CHARACTER}. If passed something other than <tt>nil</tt> or
63
+ # a single-character String, raises {InvalidIntersectionCharacterError}.
64
+ # @param [nil, String] truncation_indicator Determines the character used to indicate that a
65
+ # cell's content has been truncated. If omitted or passed <tt>nil</tt>,
66
+ # defaults to {DEFAULT_TRUNCATION_INDICATOR}. If passed something other than <tt>nil</tt> or
67
+ # a single-character String, raises {InvalidTruncationIndicatorError}.
49
68
  # @return [Table] a new Table
50
69
  # @raise [InvalidColumnLabelError] if non-unique Symbols are provided to columns.
70
+ # @raise [InvalidHorizontalRuleCharacterError] if invalid argument passed to horizontal_rule_character.
71
+ # @raise [InvalidVerticalRuleCharacterError] if invalid argument passed to vertical_rule_character.
51
72
  def initialize(sources, columns: [], column_width: nil, header_frequency: :start,
52
- wrap_header_cells_to: nil, wrap_body_cells_to: nil)
73
+ wrap_header_cells_to: nil, wrap_body_cells_to: nil, horizontal_rule_character: nil,
74
+ vertical_rule_character: nil, intersection_character: nil, truncation_indicator: nil)
53
75
 
54
76
  @sources = sources
55
77
  @header_frequency = header_frequency
56
78
  @wrap_header_cells_to = wrap_header_cells_to
57
79
  @wrap_body_cells_to = wrap_body_cells_to
58
-
59
80
  @default_column_width = (column_width || DEFAULT_COLUMN_WIDTH)
60
81
 
82
+ @horizontal_rule_character = validate_character(horizontal_rule_character,
83
+ DEFAULT_HORIZONTAL_RULE_CHARACTER, InvalidHorizontalRuleCharacterError, "horizontal rule character")
84
+ @vertical_rule_character = validate_character(vertical_rule_character,
85
+ DEFAULT_VERTICAL_RULE_CHARACTER, InvalidVerticalRuleCharacterError, "vertical rule character")
86
+ @intersection_character = validate_character(intersection_character,
87
+ DEFAULT_INTERSECTION_CHARACTER, InvalidIntersectionCharacterError, "intersection character")
88
+ @truncation_indicator = validate_character(truncation_indicator,
89
+ DEFAULT_TRUNCATION_INDICATOR, InvalidTruncationIndicatorError, "truncation indicator")
90
+
61
91
  @column_registry = { }
62
92
  columns.each { |item| add_column(item) }
63
93
 
@@ -166,9 +196,9 @@ module Tabulo
166
196
  #
167
197
  def horizontal_rule
168
198
  inner = column_registry.map do |_, column|
169
- surround(column.horizontal_rule, HORIZONTAL_RULE_CHARACTER)
199
+ @horizontal_rule_character * (column.width + 2)
170
200
  end
171
- surround_join(inner, CORNER_CHARACTER)
201
+ surround_join(inner, @intersection_character)
172
202
  end
173
203
 
174
204
  # Reset all the column widths so that each column is *just* wide enough to accommodate
@@ -278,7 +308,7 @@ module Tabulo
278
308
  append_truncator = (cell_truncated && subrow_index + 1 == row_height)
279
309
 
280
310
  lpad = PADDING_CHARACTER
281
- rpad = (append_truncator ? TRUNCATION_INDICATOR : PADDING_CHARACTER)
311
+ rpad = (append_truncator ? @truncation_indicator : PADDING_CHARACTER)
282
312
 
283
313
  inner =
284
314
  if subrow_index < num_subcells
@@ -290,7 +320,7 @@ module Tabulo
290
320
  "#{lpad}#{inner}#{rpad}"
291
321
  end
292
322
 
293
- surround_join(subrow_components, VERTICAL_RULE_CHARACTER)
323
+ surround_join(subrow_components, @vertical_rule_character)
294
324
  end
295
325
 
296
326
  join_lines(subrows)
@@ -311,6 +341,21 @@ module Tabulo
311
341
  lines.join($/) # join strings with cross-platform newline
312
342
  end
313
343
 
344
+ # @!visibility private
345
+ def validate_character(character, default, exception_class, message_fragment)
346
+ case (c = (character || default))
347
+ when nil
348
+ ; # do nothing
349
+ when String
350
+ if c.length != 1
351
+ raise exception_class, "#{message_fragment} is neither nil nor a single-character String"
352
+ end
353
+ else
354
+ raise exception_class, "#{message_fragment} is neither nil nor a single-character String"
355
+ end
356
+ c
357
+ end
358
+
314
359
  # @!visibility private
315
360
  # @return [Integer] the length of the longest segment of str when split by newlines
316
361
  def wrapped_width(str)
@@ -1,3 +1,3 @@
1
1
  module Tabulo
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -23,6 +23,11 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.required_ruby_version = ">= 2.1.10"
25
25
 
26
+ spec.metadata = {
27
+ "source_code_uri" => "https://github.com/matt-harvey/tabulo",
28
+ "changelog_uri" => "https://raw.githubusercontent.com/matt-harvey/tabulo/master/CHANGELOG.md"
29
+ }
30
+
26
31
  spec.add_development_dependency "bundler", "~> 1.16.0"
27
32
  spec.add_development_dependency "rake", "~> 11.0"
28
33
  spec.add_development_dependency "rspec", "~> 3.0"
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.0.1
4
+ version: 1.1.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-12-13 00:00:00.000000000 Z
11
+ date: 2018-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -168,7 +168,9 @@ files:
168
168
  homepage: https://matt-harvey.github.io/tabulo
169
169
  licenses:
170
170
  - MIT
171
- metadata: {}
171
+ metadata:
172
+ source_code_uri: https://github.com/matt-harvey/tabulo
173
+ changelog_uri: https://raw.githubusercontent.com/matt-harvey/tabulo/master/CHANGELOG.md
172
174
  post_install_message:
173
175
  rdoc_options: []
174
176
  require_paths: