tty-table 0.10.0 → 0.11.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 (150) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +67 -3
  4. data/Rakefile +2 -0
  5. data/lib/tty-table.rb +0 -3
  6. data/lib/tty/table.rb +35 -12
  7. data/lib/tty/table/alignment_set.rb +2 -2
  8. data/lib/tty/table/border.rb +6 -3
  9. data/lib/tty/table/border/ascii.rb +1 -1
  10. data/lib/tty/table/border/null.rb +3 -2
  11. data/lib/tty/table/border/row_line.rb +1 -1
  12. data/lib/tty/table/border/unicode.rb +1 -2
  13. data/lib/tty/table/border_dsl.rb +3 -3
  14. data/lib/tty/table/border_options.rb +21 -1
  15. data/lib/tty/table/column_constraint.rb +1 -1
  16. data/lib/tty/table/columns.rb +0 -1
  17. data/lib/tty/table/empty.rb +2 -0
  18. data/lib/tty/table/error.rb +1 -1
  19. data/lib/tty/table/field.rb +1 -1
  20. data/lib/tty/table/header.rb +1 -1
  21. data/lib/tty/table/indentation.rb +2 -3
  22. data/lib/tty/table/operation/alignment.rb +8 -6
  23. data/lib/tty/table/operation/escape.rb +1 -1
  24. data/lib/tty/table/operation/filter.rb +1 -1
  25. data/lib/tty/table/operation/padding.rb +1 -9
  26. data/lib/tty/table/operation/truncation.rb +1 -1
  27. data/lib/tty/table/operation/wrapped.rb +1 -1
  28. data/lib/tty/table/operations.rb +1 -1
  29. data/lib/tty/table/options.rb +1 -1
  30. data/lib/tty/table/orientation.rb +1 -1
  31. data/lib/tty/table/orientation/horizontal.rb +1 -1
  32. data/lib/tty/table/orientation/vertical.rb +1 -1
  33. data/lib/tty/table/renderer.rb +4 -4
  34. data/lib/tty/table/renderer/ascii.rb +1 -1
  35. data/lib/tty/table/renderer/basic.rb +19 -20
  36. data/lib/tty/table/renderer/unicode.rb +1 -1
  37. data/lib/tty/table/row.rb +2 -2
  38. data/lib/tty/table/transformation.rb +2 -2
  39. data/lib/tty/table/validatable.rb +1 -1
  40. data/lib/tty/table/version.rb +3 -1
  41. data/spec/spec_helper.rb +1 -1
  42. data/spec/unit/access_spec.rb +1 -3
  43. data/spec/unit/add_row_spec.rb +1 -3
  44. data/spec/unit/alignment_set/each_spec.rb +1 -3
  45. data/spec/unit/alignment_set/new_spec.rb +1 -3
  46. data/spec/unit/alignment_set/to_ary_spec.rb +1 -3
  47. data/spec/unit/alignment_spec.rb +1 -3
  48. data/spec/unit/border/ascii/rendering_spec.rb +1 -3
  49. data/spec/unit/border/new_spec.rb +1 -3
  50. data/spec/unit/border/null/rendering_spec.rb +1 -3
  51. data/spec/unit/border/options/from_spec.rb +1 -3
  52. data/spec/unit/border/options/new_spec.rb +1 -3
  53. data/spec/unit/border/unicode/rendering_spec.rb +1 -3
  54. data/spec/unit/border_options/new_spec.rb +1 -3
  55. data/spec/unit/border_options/update_spec.rb +1 -3
  56. data/spec/unit/column_constraint/enforce_spec.rb +1 -3
  57. data/spec/unit/column_constraint/widths_spec.rb +1 -3
  58. data/spec/unit/columns/extract_widths_spec.rb +1 -1
  59. data/spec/unit/columns/total_width_spec.rb +0 -1
  60. data/spec/unit/columns/widths_from_spec.rb +1 -1
  61. data/spec/unit/data_spec.rb +1 -3
  62. data/spec/unit/each_spec.rb +1 -3
  63. data/spec/unit/each_with_index_spec.rb +1 -3
  64. data/spec/unit/empty_spec.rb +1 -3
  65. data/spec/unit/eql_spec.rb +1 -3
  66. data/spec/unit/field/equality_spec.rb +1 -3
  67. data/spec/unit/field/length_spec.rb +1 -3
  68. data/spec/unit/field/lines_spec.rb +1 -3
  69. data/spec/unit/field/new_spec.rb +1 -3
  70. data/spec/unit/field/width_spec.rb +1 -3
  71. data/spec/unit/filter_spec.rb +1 -3
  72. data/spec/unit/header/call_spec.rb +1 -3
  73. data/spec/unit/header/color_spec.rb +1 -3
  74. data/spec/unit/header/equality_spec.rb +1 -3
  75. data/spec/unit/header/height_spec.rb +1 -3
  76. data/spec/unit/header/new_spec.rb +1 -4
  77. data/spec/unit/header/set_spec.rb +1 -3
  78. data/spec/unit/header/to_ary_spec.rb +1 -3
  79. data/spec/unit/header_spec.rb +1 -3
  80. data/spec/unit/indentation/indent_spec.rb +1 -3
  81. data/spec/unit/new_spec.rb +1 -3
  82. data/spec/unit/operation/alignment/call_spec.rb +1 -3
  83. data/spec/unit/operation/escape/call_spec.rb +1 -3
  84. data/spec/unit/operation/filter/call_spec.rb +1 -3
  85. data/spec/unit/operation/truncation/call_spec.rb +1 -3
  86. data/spec/unit/operation/wrapped/call_spec.rb +1 -3
  87. data/spec/unit/operations/new_spec.rb +1 -1
  88. data/spec/unit/options/access_spec.rb +1 -3
  89. data/spec/unit/options_spec.rb +1 -3
  90. data/spec/unit/orientation_spec.rb +1 -3
  91. data/spec/unit/padding_spec.rb +1 -3
  92. data/spec/unit/properties_spec.rb +1 -3
  93. data/spec/unit/render_repeat_spec.rb +1 -4
  94. data/spec/unit/render_spec.rb +1 -3
  95. data/spec/unit/render_with_spec.rb +1 -3
  96. data/spec/unit/renderer/ascii/coloring_spec.rb +16 -3
  97. data/spec/unit/renderer/ascii/indentation_spec.rb +1 -3
  98. data/spec/unit/renderer/ascii/multiline_spec.rb +1 -3
  99. data/spec/unit/renderer/ascii/padding_spec.rb +1 -3
  100. data/spec/unit/renderer/ascii/render_spec.rb +1 -3
  101. data/spec/unit/renderer/ascii/resizing_spec.rb +1 -3
  102. data/spec/unit/renderer/ascii/separator_spec.rb +14 -4
  103. data/spec/unit/renderer/basic/alignment_spec.rb +1 -3
  104. data/spec/unit/renderer/basic/coloring_spec.rb +1 -3
  105. data/spec/unit/renderer/basic/extract_column_widths_spec.rb +1 -3
  106. data/spec/unit/renderer/basic/filter_spec.rb +1 -3
  107. data/spec/unit/renderer/basic/indentation_spec.rb +1 -3
  108. data/spec/unit/renderer/basic/multiline_spec.rb +1 -3
  109. data/spec/unit/renderer/basic/new_spec.rb +1 -3
  110. data/spec/unit/renderer/basic/options_spec.rb +1 -3
  111. data/spec/unit/renderer/basic/padding_spec.rb +1 -3
  112. data/spec/unit/renderer/basic/render_spec.rb +1 -3
  113. data/spec/unit/renderer/basic/resizing_spec.rb +1 -3
  114. data/spec/unit/renderer/basic/separator_spec.rb +1 -3
  115. data/spec/unit/renderer/basic/single_row_separator_spec.rb +80 -0
  116. data/spec/unit/renderer/basic/truncation_spec.rb +1 -3
  117. data/spec/unit/renderer/basic/wrapping_spec.rb +1 -3
  118. data/spec/unit/renderer/border_spec.rb +1 -3
  119. data/spec/unit/renderer/render_spec.rb +1 -3
  120. data/spec/unit/renderer/select_spec.rb +1 -3
  121. data/spec/unit/renderer/unicode/coloring_spec.rb +1 -3
  122. data/spec/unit/renderer/unicode/indentation_spec.rb +1 -3
  123. data/spec/unit/renderer/unicode/padding_spec.rb +1 -3
  124. data/spec/unit/renderer/unicode/render_spec.rb +1 -3
  125. data/spec/unit/renderer/unicode/separator_spec.rb +13 -3
  126. data/spec/unit/renderer_spec.rb +1 -3
  127. data/spec/unit/rotate_spec.rb +1 -3
  128. data/spec/unit/row/access_spec.rb +1 -3
  129. data/spec/unit/row/call_spec.rb +1 -3
  130. data/spec/unit/row/data_spec.rb +1 -3
  131. data/spec/unit/row/each_spec.rb +1 -3
  132. data/spec/unit/row/equality_spec.rb +1 -3
  133. data/spec/unit/row/height_spec.rb +1 -3
  134. data/spec/unit/row/new_spec.rb +1 -3
  135. data/spec/unit/row/to_ary_spec.rb +1 -3
  136. data/spec/unit/to_s_spec.rb +1 -1
  137. data/spec/unit/transformation/extract_tuples_spec.rb +1 -3
  138. data/spec/unit/utf_spec.rb +1 -3
  139. data/spec/unit/validatable/validate_options_spec.rb +1 -3
  140. data/spec/unit/validatable_spec.rb +1 -3
  141. data/tasks/console.rake +1 -0
  142. data/tty-table.gemspec +19 -10
  143. metadata +21 -27
  144. data/.gitignore +0 -14
  145. data/.rspec +0 -3
  146. data/.travis.yml +0 -26
  147. data/CODE_OF_CONDUCT.md +0 -49
  148. data/Gemfile +0 -17
  149. data/appveyor.yml +0 -21
  150. data/benchmarks/speed.rb +0 -39
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module TTY
@@ -27,8 +26,8 @@ module TTY
27
26
  #
28
27
  # @api public
29
28
  def insert_indentation(line, indentation)
30
- line = line.is_a?(Array) ? line[0] : line
31
- line.insert(0, ' ' * indentation) if line
29
+ line = Array(line)[0]
30
+ ' ' * indentation + line.to_s if line
32
31
  end
33
32
  module_function :insert_indentation
34
33
  end # Indentation
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'strings'
4
4
 
@@ -19,10 +19,14 @@ module TTY
19
19
 
20
20
  # Evaluate alignment of the provided row
21
21
  #
22
+ # @param [TTY::Table::Field] field
23
+ # the table field
24
+ #
22
25
  # @param [Array] row
23
26
  # the table row
24
- # @param [Hash] options
25
- # the table options
27
+ #
28
+ # @param [Integer] col
29
+ # the table column index
26
30
  #
27
31
  # @return [TTY::Table::Field]
28
32
  #
@@ -42,11 +46,9 @@ module TTY
42
46
  # @param [TTY::Table::Field] field
43
47
  # the table field
44
48
  #
45
- # @param [Integer] co
49
+ # @param [Integer] col
46
50
  # the table column index
47
51
  #
48
- # @param [Hash] options
49
- #
50
52
  # @return [TTY::Table::Field]
51
53
  #
52
54
  # @api private
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module TTY
4
4
  class Table
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module TTY
4
4
  class Table
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'strings'
4
4
 
@@ -13,8 +13,6 @@ module TTY
13
13
  #
14
14
  # @param [Strings::Padder] padding
15
15
  #
16
- # @param [Array[Integer]] widths
17
- #
18
16
  # @api public
19
17
  def initialize(padding)
20
18
  @padding = padding
@@ -25,12 +23,6 @@ module TTY
25
23
  # @param [TTY::Table::Field] field
26
24
  # the table field
27
25
  #
28
- # @param [Integer] row
29
- # the field row index
30
- #
31
- # @param [Integer] col
32
- # the field column index
33
- #
34
26
  # @return [TTY::Table::Field]
35
27
  #
36
28
  # @api public
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'strings'
4
4
 
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'strings'
4
4
 
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module TTY
4
4
  class Table
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'delegate'
4
4
 
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'orientation/horizontal'
4
4
  require_relative 'orientation/vertical'
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module TTY
4
4
  class Table
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module TTY
4
4
  class Table
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'error'
4
4
  require_relative 'renderer/basic'
@@ -21,11 +21,11 @@ module TTY
21
21
 
22
22
  # Select renderer class based on string name.
23
23
  #
24
- # The possible values for renderer are
24
+ # The possible values for type are
25
25
  # [:basic, :ascii, :unicode]
26
26
  #
27
- # @param [Symbol] renderer
28
- # the renderer used for displaying table
27
+ # @param [Symbol] type
28
+ # the renderer type used for displaying table
29
29
  #
30
30
  # @return [TTY::Table::Renderer]
31
31
  #
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative '../border/ascii'
4
4
  require_relative '../renderer/basic'
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'tty-screen'
4
4
  require 'strings'
@@ -151,6 +151,7 @@ module TTY
151
151
  elsif !not_set
152
152
  @border = TTY::Table::BorderOptions.from(options)
153
153
  end
154
+ @border.separator ||= @table.separators unless @table.separators.empty?
154
155
  @border
155
156
  end
156
157
  alias_method :border=, :border
@@ -251,7 +252,7 @@ module TTY
251
252
  rows_with_border = render_rows(data_border)
252
253
  bottom_line = data_border.bottom_line
253
254
 
254
- Indentation.indent(bottom_line, @indent) if bottom_line
255
+ bottom_line = Indentation.indent(bottom_line, @indent) if bottom_line
255
256
 
256
257
  [header, rows_with_border, bottom_line].compact
257
258
  end
@@ -261,7 +262,7 @@ module TTY
261
262
  # @param [TTY::Table::Row, TTY::Table::Header] row
262
263
  # the first row in the table
263
264
  #
264
- # @param [TTY::Table::Border] data_boder
265
+ # @param [TTY::Table::Border] data_border
265
266
  # the border for this table
266
267
  #
267
268
  # @return [String]
@@ -269,17 +270,15 @@ module TTY
269
270
  # @api private
270
271
  def render_header(row, data_border)
271
272
  top_line = data_border.top_line
272
- if row.is_a?(TTY::Table::Header)
273
- header = [top_line, data_border.row_line(row), data_border.separator]
274
- Indentation.indent(header.compact, @indent)
275
- else
276
- top_line
277
- end
273
+ return top_line unless row.is_a?(TTY::Table::Header)
274
+ separator = data_border.separator if !border.separator || border.separator?(0)
275
+ header = [top_line, data_border.row_line(row), separator]
276
+ Indentation.indent(header.compact, @indent)
278
277
  end
279
278
 
280
279
  # Format the rows
281
280
  #
282
- # @param [TTY::Table::Border] data_boder
281
+ # @param [TTY::Table::Border] data_border
283
282
  # the border for this table
284
283
  #
285
284
  # @return [Arrays[String]]
@@ -288,8 +287,9 @@ module TTY
288
287
  def render_rows(data_border)
289
288
  rows = table.rows
290
289
  size = rows.size
290
+ offset = table.first.is_a?(TTY::Table::Header) ? 1 : 0
291
291
  rows.each_with_index.map do |row, index|
292
- render_row(row, data_border, size != (index += 1))
292
+ render_row(row, index+offset, data_border, size != (index + 1))
293
293
  end
294
294
  end
295
295
 
@@ -298,21 +298,20 @@ module TTY
298
298
  # @param [Array] row
299
299
  # a row to decorate
300
300
  #
301
- # @param [TTY::Table::Border] data_boder
301
+ # @param [TTY::Table::Border] data_border
302
302
  # the border for this table
303
303
  #
304
- # @param [Boolean] is_last_row
304
+ # @param [Boolean] is_not_last_row
305
305
  #
306
306
  # @api private
307
- def render_row(row, data_border, is_last_row)
307
+ def render_row(row, index, data_border, is_not_last_row)
308
308
  separator = data_border.separator
309
309
  row_line = data_border.row_line(row)
310
-
311
- if (border.separator == TTY::Table::Border::EACH_ROW) && is_last_row
312
- line = [row_line, separator]
313
- else
314
- line = row_line
315
- end
310
+ line = if border.separator?(index) && is_not_last_row
311
+ [row_line, separator]
312
+ else
313
+ row_line
314
+ end
316
315
  Indentation.indent(line, @indent)
317
316
  end
318
317
  end # Basic
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative '../border/unicode'
4
4
 
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable'
4
4
 
@@ -101,7 +101,7 @@ module TTY
101
101
  # Lookup a value in the row given an attribute allowing for Array or
102
102
  # Hash like indexing
103
103
  #
104
- # @exmaple
104
+ # @example
105
105
  # row[1]
106
106
  # row[:id]
107
107
  # row.call(:id)
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module TTY
4
4
  class Table
@@ -26,7 +26,7 @@ module TTY
26
26
 
27
27
  # Group hash keys into header and values into rows
28
28
  #
29
- # @params [Hash] value
29
+ # @param [Hash] value
30
30
  #
31
31
  # @api public
32
32
  def self.group_header_and_rows(value)
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'error'
4
4
 
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TTY
2
4
  class Table
3
- VERSION = '0.10.0'.freeze
5
+ VERSION = "0.11.0"
4
6
  end # Table
5
7
  end # TTY
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  if ENV['COVERAGE'] || ENV['TRAVIS']
4
4
  require 'simplecov'
@@ -1,6 +1,4 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table, 'access' do
6
4
  let(:header) { [:head1, :head2] }
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table, '#<<' do
6
4
  let(:rows) { ['a', 'b', 'c'] }
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table::AlignmentSet, '#each' do
6
4
  let(:alignments) { [:left, :center, :right] }
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table::AlignmentSet, '#new' do
6
4
  let(:object) { described_class }
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table::AlignmentSet, '#to_ary' do
6
4
  let(:argument) { [:center, :left] }
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table, 'alignment' do
6
4
  it "aligns table columns when rendering" do
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table::Border::ASCII, '#rendering' do
6
4
 
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table::Border, '#new' do
6
4
  let(:row) { [] }
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table::Border::Null, '#rendering' do
6
4
  let(:border) { nil }
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table::BorderOptions, '#from' do
6
4
 
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table::BorderOptions, '.new' do
6
4
 
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table::Border::Unicode, '#rendering' do
6
4
 
@@ -1,6 +1,4 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table::BorderOptions do
6
4
 
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
1
+ # frozen_string_literal: true
4
2
 
5
3
  RSpec.describe TTY::Table::BorderOptions, '.update' do
6
4