term_utils 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -2
  3. data/COPYING +3 -3
  4. data/README.md +51 -16
  5. data/doc/TermUtils.html +9 -9
  6. data/doc/TermUtils/AP.html +48 -159
  7. data/doc/TermUtils/AP/Article.html +48 -46
  8. data/doc/TermUtils/AP/ArticleResult.html +584 -0
  9. data/doc/TermUtils/AP/Flag.html +294 -77
  10. data/doc/TermUtils/AP/NoSuchValueError.html +13 -13
  11. data/doc/TermUtils/AP/Parameter.html +885 -97
  12. data/doc/TermUtils/AP/ParameterResult.html +980 -0
  13. data/doc/TermUtils/{FF/Cursor/Context.html → AP/ParameterWalkerHooks.html} +59 -59
  14. data/doc/TermUtils/AP/ParseError.html +13 -13
  15. data/doc/TermUtils/AP/Parser.html +174 -142
  16. data/doc/TermUtils/AP/Result.html +200 -527
  17. data/doc/TermUtils/AP/Syntax.html +102 -392
  18. data/doc/TermUtils/AP/SyntaxError.html +13 -13
  19. data/doc/TermUtils/AP/Walker.html +686 -0
  20. data/doc/TermUtils/FF.html +10 -10
  21. data/doc/TermUtils/FF/Config.html +201 -33
  22. data/doc/TermUtils/FF/Context.html +585 -0
  23. data/doc/TermUtils/FF/Entry.html +626 -0
  24. data/doc/TermUtils/FF/Query.html +402 -66
  25. data/doc/TermUtils/PropertyTreeNode.html +302 -188
  26. data/doc/TermUtils/Tab.html +90 -83
  27. data/doc/TermUtils/Tab/Column.html +94 -92
  28. data/doc/TermUtils/Tab/Header.html +26 -26
  29. data/doc/TermUtils/Tab/Holder.html +74 -74
  30. data/doc/TermUtils/Tab/Printer.html +42 -42
  31. data/doc/TermUtils/Tab/Table.html +124 -128
  32. data/doc/TermUtils/Tab/TableError.html +11 -11
  33. data/doc/_index.html +48 -34
  34. data/doc/class_list.html +3 -3
  35. data/doc/css/style.css +2 -2
  36. data/doc/file.README.html +64 -31
  37. data/doc/file_list.html +2 -2
  38. data/doc/frames.html +2 -2
  39. data/doc/index.html +64 -31
  40. data/doc/js/app.js +14 -3
  41. data/doc/method_list.html +387 -211
  42. data/doc/top-level-namespace.html +6 -6
  43. data/lib/term_utils.rb +8 -1
  44. data/lib/term_utils/ap.rb +41 -30
  45. data/lib/term_utils/ap/article.rb +14 -8
  46. data/lib/term_utils/ap/flag.rb +36 -19
  47. data/lib/term_utils/ap/parameter.rb +87 -18
  48. data/lib/term_utils/ap/parser.rb +141 -115
  49. data/lib/term_utils/ap/result.rb +207 -160
  50. data/lib/term_utils/ap/syntax.rb +52 -68
  51. data/lib/term_utils/ff.rb +11 -2
  52. data/lib/term_utils/ff/config.rb +20 -8
  53. data/lib/term_utils/{ap/no_such_value_error.rb → ff/entry.rb} +25 -7
  54. data/lib/term_utils/ff/query.rb +93 -14
  55. data/lib/term_utils/property_tree_node.rb +47 -19
  56. data/lib/term_utils/tab.rb +102 -58
  57. data/term_utils.gemspec +4 -4
  58. metadata +12 -14
  59. data/doc/TermUtils/AP/Element.html +0 -1025
  60. data/doc/TermUtils/AP/Level.html +0 -638
  61. data/doc/TermUtils/FF/Cursor.html +0 -929
  62. data/lib/term_utils/ap/element.rb +0 -78
  63. data/lib/term_utils/ap/level.rb +0 -57
  64. data/lib/term_utils/ap/parse_error.rb +0 -27
  65. data/lib/term_utils/ap/syntax_error.rb +0 -27
  66. data/lib/term_utils/ff/cursor.rb +0 -153
@@ -1,4 +1,6 @@
1
- # Copyright (C) 2019 Thomas Baron
1
+ # frozen-string-literal: true
2
+
3
+ # Copyright (C) 2020 Thomas Baron
2
4
  #
3
5
  # This file is part of term_utils.
4
6
  #
@@ -13,6 +15,7 @@
13
15
  #
14
16
  # You should have received a copy of the GNU General Public License
15
17
  # along with term_utils. If not, see <https://www.gnu.org/licenses/>.
18
+
16
19
  module TermUtils
17
20
  # The tab module provides a way to print formatted tables.
18
21
  module Tab
@@ -22,51 +25,56 @@ module TermUtils
22
25
  super
23
26
  end
24
27
  end
28
+
25
29
  # Creates initial column properties.
26
30
  # @return [Hash] `:offset`, `:column_separator_width`.
27
31
  def self.init_table_props
28
- {:offset => 0, :column_separator_width => 2}
32
+ { offset: 0, column_separator_width: 2 }
29
33
  end
34
+
30
35
  # Creates initial column properties.
31
36
  # @return [Hash] `:width`, `:align`, `:fixed`, `:ellipsis`, `:format`.
32
37
  def self.init_column_props
33
- {:width => 8, :align => :left, :fixed => false, :ellipsis => "?", :format => nil}
38
+ { width: 8, align: :left, fixed: false, ellipsis: '?', format: nil }
34
39
  end
40
+
35
41
  # Assigns table properties.
36
42
  # @param target [Hash]
37
43
  # @param source [Hash] `:offset`, `:column_separator_width`.
38
44
  # @return [Hash]
39
45
  def self.assign_table_props(target, source)
40
- if (source.has_key? :offset) && (source[:offset].is_a? Integer) && (source[:offset] >= 0)
46
+ if (source.key? :offset) && (source[:offset].is_a? Integer) && (source[:offset] >= 0)
41
47
  target[:offset] = source[:offset]
42
48
  end
43
- if (source.has_key? :column_separator_width) && (source[:column_separator_width].is_a? Integer) && (source[:column_separator_width] > 0)
49
+ if (source.key? :column_separator_width) && (source[:column_separator_width].is_a? Integer) && source[:column_separator_width].positive?
44
50
  target[:column_separator_width] = source[:column_separator_width]
45
51
  end
46
52
  target
47
53
  end
54
+
48
55
  # Assigns column properties.
49
56
  # @param target [Hash]
50
57
  # @param source [Hash] `:width`, `:align`, `:fixed`, `:ellipsis`, `:format`.
51
58
  # @return [Hash]
52
59
  def self.assign_column_props(target, source)
53
- if (source.has_key? :width) && (source[:width].is_a? Integer) && (source[:width] > 0)
60
+ if (source.key? :width) && (source[:width].is_a? Integer) && source[:width].positive?
54
61
  target[:width] = source[:width]
55
62
  end
56
- if (source.has_key? :align) && %i[left right].index(source[:align])
63
+ if (source.key? :align) && %i[left right].index(source[:align])
57
64
  target[:align] = source[:align]
58
65
  end
59
- if (source.has_key? :fixed) && (!!source[:fixed] == source[:fixed])
66
+ if (source.key? :fixed) && (!!source[:fixed] == source[:fixed])
60
67
  target[:fixed] = source[:fixed]
61
68
  end
62
- if (source.has_key? :ellipsis) && (source[:ellipsis].is_a? String)
69
+ if (source.key? :ellipsis) && (source[:ellipsis].is_a? String)
63
70
  target[:ellipsis] = source[:ellipsis]
64
71
  end
65
- if (source.has_key? :format) && ((source[:ellipsis] == nil) || (source[:ellipsis].is_a? Proc) || (source[:ellipsis].is_a? String))
72
+ if (source.key? :format) && (source[:ellipsis].nil? || (source[:ellipsis].is_a? Proc) || (source[:ellipsis].is_a? String))
66
73
  target[:format] = source[:format]
67
74
  end
68
75
  target
69
76
  end
77
+
70
78
  # Aligns and cuts a given string.
71
79
  # @param src [String]
72
80
  # @param align [Symbol] `:left`, `:right`.
@@ -75,32 +83,31 @@ module TermUtils
75
83
  # @param ellipsis [String] The ellipsis when not fixed.
76
84
  # @return [String]
77
85
  def self.align_cut(src, align, fixed, width, ellipsis)
78
- res = src
79
86
  if align == :left
80
87
  # Align left
81
88
  if fixed && (src.length > width)
82
89
  if ellipsis.length >= width
83
- res = ellipsis[0..(width - 1)]
90
+ ellipsis[0..(width - 1)]
84
91
  else
85
- res = "%s%s" % [src[0..(width - (ellipsis.length + 1))], ellipsis]
92
+ format '%<value>s%<ellipsis>s', value: src[0..(width - (ellipsis.length + 1))], ellipsis: ellipsis
86
93
  end
87
94
  else
88
- res = "%-*s" % [width, src]
95
+ src.ljust(width)
89
96
  end
90
97
  elsif align == :right
91
98
  # Align right
92
99
  if fixed && (src.length > width)
93
100
  if ellipsis.length >= width
94
- res = ellipsis[0..(width - 1)]
101
+ ellipsis[0..(width - 1)]
95
102
  else
96
- res = "%s%s" % [ellipsis, src[(src.length - width + ellipsis.length)..(src.length - 1)]]
103
+ format '%<ellipsis>s%<value>s', ellipsis: ellipsis, value: src[(src.length - width + ellipsis.length)..(src.length - 1)]
97
104
  end
98
105
  else
99
- res = "%*s" % [width, src]
106
+ src.rjust(width)
100
107
  end
101
108
  end
102
- res
103
109
  end
110
+
104
111
  # Represents a table.
105
112
  class Table
106
113
  # @return [Symbol]
@@ -113,6 +120,7 @@ module TermUtils
113
120
  attr_accessor :column_defaults
114
121
  # @return [Array<Tab::Column>]
115
122
  attr_accessor :columns
123
+
116
124
  # @param opts [Hash]
117
125
  # @option opts [Symbol] :id
118
126
  # @option opts [Integer] :offset
@@ -122,18 +130,16 @@ module TermUtils
122
130
  @id = opts.fetch(:id, nil)
123
131
  @offset = opts.fetch(:offset)
124
132
  @column_separator_width = opts.fetch(:column_separator_width)
125
- if opts.has_key? :column_defaults
126
- @column_defaults = opts[:column_defaults].dup
127
- else
128
- @column_defaults = TermUtils::Tab.default_column_props
129
- end
133
+ @column_defaults = opts.key?(:column_defaults) ? opts[:column_defaults].dup : TermUtils::Tab.default_column_props
130
134
  @columns = []
131
135
  end
136
+
132
137
  # Returns the properties of this one.
133
138
  # @return [Hash]
134
139
  def props
135
- {:offset => @offset, :column_separator_width => @column_separator_width}
140
+ { offset: @offset, column_separator_width: @column_separator_width }
136
141
  end
142
+
137
143
  # Sets column default properties.
138
144
  # @param opts [Hash]
139
145
  # @option opts [Integer] :width
@@ -144,6 +150,7 @@ module TermUtils
144
150
  def set_column_defaults(opts = {})
145
151
  TermUtils::Tab.assign_column_props(@column_defaults, opts)
146
152
  end
153
+
147
154
  # Defines a column.
148
155
  # @param id [Symbol]
149
156
  # @param opts [Hash]
@@ -156,24 +163,26 @@ module TermUtils
156
163
  def define_column(id, opts = {}, &block)
157
164
  col = @columns.find { |c| c.id == id }
158
165
  if col
159
- block.call(col) if block
166
+ block&.call(col)
160
167
  col.validate
161
168
  else
162
169
  opts[:id] = id
163
170
  opts[:index] = @columns.length
164
171
  col = Column.new(@column_defaults.merge(opts))
165
- block.call(col) if block
172
+ block&.call(col)
166
173
  col.validate
167
174
  @columns << col
168
175
  end
169
176
  col
170
177
  end
178
+
171
179
  # Finds a column.
172
180
  # @param id [Symbol]
173
181
  # @return [Tab::Column, nil]
174
182
  def find_column(id)
175
183
  @columns.find { |c| c.id == id }
176
184
  end
185
+
177
186
  # Creates a new table printer.
178
187
  # @param io [#puts]
179
188
  # @param opts [Hash]
@@ -182,9 +191,10 @@ module TermUtils
182
191
  # @return [Tab::Printer]
183
192
  def printer(io, opts = {}, &block)
184
193
  ptr = Printer.new(self, io, props.merge(opts))
185
- block.call(ptr) if block
194
+ block&.call(ptr)
186
195
  ptr
187
196
  end
197
+
188
198
  # Prints a header row.
189
199
  # @param io [#puts]
190
200
  # @param values [Array<Object>, Hash<Symbol, Object>]
@@ -203,17 +213,19 @@ module TermUtils
203
213
  vals << values[col.id]
204
214
  end
205
215
  end
206
- raise TermUtils::Tab::TableError, "wrong values (not array)" unless vals.is_a? Array
216
+ raise TermUtils::Tab::TableError, 'wrong values (not array)' unless vals.is_a? Array
217
+
207
218
  offset = opts.fetch(:offset)
208
219
  column_separator_width = opts.fetch(:column_separator_width)
209
220
  sb = StringIO.new
210
- sb << " " * offset if offset > 0
221
+ sb << ' ' * offset if offset.positive?
211
222
  @columns.each do |col|
212
- sb << " " * column_separator_width if col.index > 0
223
+ sb << ' ' * column_separator_width if col.index.positive?
213
224
  sb << col.render_header(vals[col.index])
214
225
  end
215
226
  io.puts sb.string
216
227
  end
228
+
217
229
  # Prints a data row.
218
230
  # @param io [#puts]
219
231
  # @param values [Array<Object>, Hash<Symbol, Object>]
@@ -230,17 +242,19 @@ module TermUtils
230
242
  vals << values[col.id]
231
243
  end
232
244
  end
233
- raise TermUtils::Tab::TableError, "wrong values (not array)" unless vals.is_a? Array
245
+ raise TermUtils::Tab::TableError, 'wrong values (not array)' unless vals.is_a? Array
246
+
234
247
  offset = opts.fetch(:offset)
235
248
  column_separator_width = opts.fetch(:column_separator_width)
236
249
  sb = StringIO.new
237
- sb << " " * offset if offset > 0
250
+ sb << ' ' * offset if offset.positive?
238
251
  @columns.each do |col|
239
- sb << " " * column_separator_width if col.index > 0
252
+ sb << ' ' * column_separator_width if col.index.positive?
240
253
  sb << col.render_data(vals[col.index])
241
254
  end
242
255
  io.puts sb.string
243
256
  end
257
+
244
258
  # Prints a separator row.
245
259
  # @param io [#puts]
246
260
  # @param opts [Hash]
@@ -251,13 +265,14 @@ module TermUtils
251
265
  offset = opts.fetch(:offset)
252
266
  column_separator_width = opts.fetch(:column_separator_width)
253
267
  sb = StringIO.new
254
- sb << " " * offset if offset > 0
268
+ sb << ' ' * offset if offset.positive?
255
269
  @columns.each do |col|
256
- sb << " " * column_separator_width if col.index > 0
257
- sb << "-" * col.width
270
+ sb << ' ' * column_separator_width if col.index.positive?
271
+ sb << '-' * col.width
258
272
  end
259
273
  io.puts sb.string
260
274
  end
275
+
261
276
  # Returns column titles.
262
277
  # @return [Hash<Symbol, String>]
263
278
  def titles
@@ -268,6 +283,7 @@ module TermUtils
268
283
  h
269
284
  end
270
285
  end
286
+
271
287
  # Represents a table column.
272
288
  class Column
273
289
  # @return [Symbol]
@@ -286,6 +302,7 @@ module TermUtils
286
302
  attr_accessor :format
287
303
  # @return [TermUtils::Tab::Header]
288
304
  attr_accessor :header
305
+
289
306
  # @param opts [Hash]
290
307
  # @option opts [Symbol] :id
291
308
  # @option opts [Integer] :index
@@ -300,31 +317,35 @@ module TermUtils
300
317
  @width = opts.fetch(:width, 8)
301
318
  @align = opts.fetch(:align, :left)
302
319
  @fixed = opts.fetch(:fixed, false)
303
- @ellipsis = opts.fetch(:ellipsis, "?")
320
+ @ellipsis = opts.fetch(:ellipsis, '?')
304
321
  @format = opts.fetch(:format, nil)
305
- @header = TermUtils::Tab::Header.new(:title => @id.to_s, :align => @align)
322
+ @header = TermUtils::Tab::Header.new(title: @id.to_s, align: @align)
306
323
  end
324
+
307
325
  # Validates the column represented by this one.
308
326
  # @return [nil]
309
327
  # @raise [TermUtils::Tab::TableError]
310
328
  def validate
311
- raise TermUtils::Tab::TableError, "missing column id (nil)" if @id.nil?
312
- raise TermUtils::Tab::TableError, "missing column index (nil)" if @index.nil?
313
- raise TermUtils::Tab::TableError, "wrong column index (not integer)" unless @index.is_a? Integer
314
- raise TermUtils::Tab::TableError, "wrong column index (not >= 0)" if @index < 0
315
- raise TermUtils::Tab::TableError, "missing column width (nil)" if @width.nil?
316
- raise TermUtils::Tab::TableError, "wrong column width (not integer)" unless @width.is_a? Integer
317
- raise TermUtils::Tab::TableError, "wrong column width (not > 0)" if @width <= 0
318
- raise TermUtils::Tab::TableError, "wrong column align (not :left or :right)" unless %i[left right].index(@align)
329
+ raise TermUtils::Tab::TableError, 'missing column id (nil)' if @id.nil?
330
+ raise TermUtils::Tab::TableError, 'missing column index (nil)' if @index.nil?
331
+ raise TermUtils::Tab::TableError, 'wrong column index (not integer)' unless @index.is_a? Integer
332
+ raise TermUtils::Tab::TableError, 'wrong column index (not >= 0)' if @index.negative?
333
+ raise TermUtils::Tab::TableError, 'missing column width (nil)' if @width.nil?
334
+ raise TermUtils::Tab::TableError, 'wrong column width (not integer)' unless @width.is_a? Integer
335
+ raise TermUtils::Tab::TableError, 'wrong column width (not > 0)' if @width <= 0
336
+ raise TermUtils::Tab::TableError, 'wrong column align (not :left or :right)' unless %i[left right].index(@align)
337
+
319
338
  @header.validate
320
339
  end
340
+
321
341
  # Renders a given header.
322
342
  # @param val [Object]
323
343
  # return [String]
324
344
  def render_header(val)
325
- src = (val.is_a? String) ? val : val.to_s
345
+ src = val.is_a?(String) ? val : val.to_s
326
346
  TermUtils::Tab.align_cut(src, @header.align, @fixed, @width, @ellipsis)
327
347
  end
348
+
328
349
  # Renders a given value.
329
350
  # @param val [Object]
330
351
  # return [String]
@@ -337,16 +358,18 @@ module TermUtils
337
358
  src = @format % val
338
359
  end
339
360
  end
340
- src = (src.is_a? String) ? src : src.to_s
361
+ src = src.is_a?(String) ? src : src.to_s
341
362
  TermUtils::Tab.align_cut(src, @align, @fixed, @width, @ellipsis)
342
363
  end
343
364
  end
365
+
344
366
  # Represents a column header.
345
367
  class Header
346
368
  # @return [String]
347
369
  attr_accessor :title
348
370
  # @return [Symbol] `:left`, `:right`.
349
371
  attr_accessor :align
372
+
350
373
  # Constructs a new Header.
351
374
  # @param opts [Hash]
352
375
  # @option opts [String] :title
@@ -355,12 +378,13 @@ module TermUtils
355
378
  @title = opts.fetch(:title)
356
379
  @align = opts.fetch(:align, :left)
357
380
  end
381
+
358
382
  # Validates the column represented by this one.
359
383
  # @return [nil]
360
384
  # @raise [TermUtils::Tab::TableError]
361
385
  def validate
362
- raise TermUtils::Tab::TableError, "missing header title (nil)" if @title.nil?
363
- raise TermUtils::Tab::TableError, "wrong header align (not :left or :right)" unless %i[left right].index(@align)
386
+ raise TermUtils::Tab::TableError, 'missing header title (nil)' if @title.nil?
387
+ raise TermUtils::Tab::TableError, 'wrong header align (not :left or :right)' unless %i[left right].index(@align)
364
388
  end
365
389
  end
366
390
  # Represents a table printer.
@@ -371,6 +395,7 @@ module TermUtils
371
395
  attr_accessor :io
372
396
  # @return [Hash]
373
397
  attr_accessor :options
398
+
374
399
  # @param table [Tab::Table]
375
400
  # @param io [IO]
376
401
  # @param options [Hash]
@@ -379,10 +404,12 @@ module TermUtils
379
404
  @io = io
380
405
  @options = options
381
406
  end
407
+
382
408
  # Prints an empty line.
383
409
  def line
384
- @io.puts ""
410
+ @io.puts
385
411
  end
412
+
386
413
  # Prints a header row.
387
414
  # @param values [Array<Object>, Hash<Symbol, Object>]
388
415
  # @param opts [Hash]
@@ -392,6 +419,7 @@ module TermUtils
392
419
  def header(values = nil, opts = nil)
393
420
  @table.print_header(@io, values, opts ? @options.merge(opts) : @options)
394
421
  end
422
+
395
423
  # Prints a data row.
396
424
  # @param values [Array<Object>, Hash<Symbol, Object>]
397
425
  # @param opts [Hash]
@@ -401,6 +429,7 @@ module TermUtils
401
429
  def data(values, opts = nil)
402
430
  @table.print_data(@io, values, opts ? @options.merge(opts) : @options)
403
431
  end
432
+
404
433
  # Prints a separator.
405
434
  # @param opts [Hash]
406
435
  # @option opts [Integer] :offset
@@ -410,7 +439,7 @@ module TermUtils
410
439
  @table.print_separator(@io, opts ? @options.merge(opts) : @options)
411
440
  end
412
441
  end
413
- # Represents a holder of tables.
442
+ # Represents a Holder of Table(s).
414
443
  class Holder
415
444
  # @return [Hash] `:offset`, `:column_separator_width`.
416
445
  attr_accessor :table_defaults
@@ -418,11 +447,14 @@ module TermUtils
418
447
  attr_accessor :column_defaults
419
448
  # @return [Hash<Symbol, Tab::Table>]
420
449
  attr_accessor :tables
421
- def initialize(opts = {})
450
+
451
+ # Creates a new Holder.
452
+ def initialize
422
453
  @table_defaults = TermUtils::Tab.init_table_props
423
454
  @column_defaults = TermUtils::Tab.init_column_props
424
455
  @tables = {}
425
456
  end
457
+
426
458
  # Sets table default properties.
427
459
  # @param opts [Hash]
428
460
  # @option opts [Integer] :offset
@@ -430,6 +462,7 @@ module TermUtils
430
462
  def set_table_defaults(opts = {})
431
463
  TermUtils::Tab.assign_table_props(@table_defaults, opts)
432
464
  end
465
+
433
466
  # Sets column default properties.
434
467
  # @param opts [Hash]
435
468
  # @option opts [Integer] :width
@@ -440,6 +473,7 @@ module TermUtils
440
473
  def set_column_defaults(opts = {})
441
474
  TermUtils::Tab.assign_column_props(@column_defaults, opts)
442
475
  end
476
+
443
477
  # Creates a new table, using default properties, without registering it.
444
478
  # @param opts [Hash]
445
479
  # @return [Tab::Table]
@@ -448,33 +482,36 @@ module TermUtils
448
482
  opts[:column_separator_width] = @table_defaults.fetch(:column_separator_width)
449
483
  opts[:column_defaults] = @column_defaults.dup
450
484
  new_tab = Table.new(opts)
451
- block.call(new_tab) if block
485
+ block&.call(new_tab)
452
486
  new_tab
453
487
  end
488
+
454
489
  # Defines a table, using default properties.
455
490
  # @param id [Symbol]
456
491
  # @param opts [Hash]
457
492
  # @return [Tab::Table]
458
493
  def define_table(id, opts = {}, &block)
459
- if @tables.has_key? id
460
- block.call(@tables[id]) if block
494
+ if @tables.key? id
495
+ block&.call(@tables[id])
461
496
  else
462
497
  opts[:id] = id
463
498
  opts[:offset] = @table_defaults.fetch(:offset)
464
499
  opts[:column_separator_width] = @table_defaults.fetch(:column_separator_width)
465
500
  opts[:column_defaults] = @column_defaults.dup
466
501
  new_tab = Table.new(opts)
467
- block.call(new_tab) if block
502
+ block&.call(new_tab)
468
503
  @tables[id] = new_tab
469
504
  end
470
505
  @tables[id]
471
506
  end
507
+
472
508
  # Finds a table.
473
509
  # @param id [Symbol]
474
510
  # @return [Tab::Table, nil]
475
511
  def find_table(id)
476
512
  @tables[id]
477
513
  end
514
+
478
515
  # Creates a new table printer.
479
516
  # @param id [Symbol]
480
517
  # @param io [IO]
@@ -486,7 +523,9 @@ module TermUtils
486
523
  find_table(id).printer(io, opts, &block)
487
524
  end
488
525
  end
489
- @@default_holder = Holder.new
526
+
527
+ @@default_holder = Holder.new # rubocop:disable Style/ClassVars
528
+
490
529
  # Sets table default properties.
491
530
  # @param opts [Hash]
492
531
  # @option opts [Integer] :offset
@@ -494,6 +533,7 @@ module TermUtils
494
533
  def self.set_table_defaults(opts = {})
495
534
  @@default_holder.set_table_defaults(opts)
496
535
  end
536
+
497
537
  # Sets column default properties.
498
538
  # @param opts [Hash]
499
539
  # @option opts [Integer] :width
@@ -504,12 +544,14 @@ module TermUtils
504
544
  def self.set_column_defaults(opts = {})
505
545
  @@default_holder.set_column_defaults(opts)
506
546
  end
547
+
507
548
  # Creates a new Table, using default properties, without registering it.
508
549
  # @param opts [Hash]
509
550
  # @return [Tab::Table]
510
551
  def self.create_table(opts = {}, &block)
511
552
  @@default_holder.create_table(opts, &block)
512
553
  end
554
+
513
555
  # Defines a new Table, using default properties, and registers it.
514
556
  # @param id [Symbol]
515
557
  # @param opts [Hash]
@@ -517,12 +559,14 @@ module TermUtils
517
559
  def self.define_table(id, opts = {}, &block)
518
560
  @@default_holder.define_table(id, opts, &block)
519
561
  end
562
+
520
563
  # Finds a registered table.
521
564
  # @param id [Symbol]
522
565
  # @return [Tab::Table, nil]
523
566
  def self.find_table(id)
524
567
  @@default_holder.find_table(id)
525
568
  end
569
+
526
570
  # Creates a new Printer for a registered Table.
527
571
  # @param id [Symbol]
528
572
  # @param io [IO]