tty-table 0.11.0 → 0.12.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 (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +104 -98
  5. data/lib/tty-table.rb +1 -1
  6. data/lib/tty/table.rb +70 -34
  7. data/lib/tty/table/alignment_set.rb +1 -3
  8. data/lib/tty/table/border.rb +50 -57
  9. data/lib/tty/table/border/ascii.rb +16 -16
  10. data/lib/tty/table/border/null.rb +19 -22
  11. data/lib/tty/table/border/row_line.rb +3 -2
  12. data/lib/tty/table/border/unicode.rb +16 -16
  13. data/lib/tty/table/border_dsl.rb +24 -22
  14. data/lib/tty/table/border_options.rb +32 -27
  15. data/lib/tty/table/column_constraint.rb +12 -9
  16. data/lib/tty/table/columns.rb +6 -6
  17. data/lib/tty/table/field.rb +46 -28
  18. data/lib/tty/table/header.rb +5 -5
  19. data/lib/tty/table/indentation.rb +7 -4
  20. data/lib/tty/table/operation/alignment.rb +1 -1
  21. data/lib/tty/table/operation/escape.rb +1 -2
  22. data/lib/tty/table/operation/padding.rb +1 -1
  23. data/lib/tty/table/operation/truncation.rb +1 -1
  24. data/lib/tty/table/operation/wrapped.rb +1 -1
  25. data/lib/tty/table/options.rb +1 -1
  26. data/lib/tty/table/orientation.rb +4 -4
  27. data/lib/tty/table/renderer.rb +8 -8
  28. data/lib/tty/table/renderer/ascii.rb +2 -2
  29. data/lib/tty/table/renderer/basic.rb +37 -40
  30. data/lib/tty/table/renderer/unicode.rb +1 -1
  31. data/lib/tty/table/row.rb +7 -7
  32. data/lib/tty/table/validatable.rb +23 -7
  33. data/lib/tty/table/version.rb +1 -1
  34. metadata +23 -272
  35. data/Rakefile +0 -10
  36. data/examples/alignment.rb +0 -10
  37. data/examples/basic.rb +0 -6
  38. data/examples/orientation.rb +0 -13
  39. data/examples/padding.rb +0 -15
  40. data/examples/resize.rb +0 -15
  41. data/spec/spec_helper.rb +0 -50
  42. data/spec/unit/access_spec.rb +0 -84
  43. data/spec/unit/add_row_spec.rb +0 -26
  44. data/spec/unit/alignment_set/each_spec.rb +0 -15
  45. data/spec/unit/alignment_set/new_spec.rb +0 -25
  46. data/spec/unit/alignment_set/to_ary_spec.rb +0 -12
  47. data/spec/unit/alignment_spec.rb +0 -69
  48. data/spec/unit/border/ascii/rendering_spec.rb +0 -88
  49. data/spec/unit/border/new_spec.rb +0 -25
  50. data/spec/unit/border/null/rendering_spec.rb +0 -128
  51. data/spec/unit/border/options/from_spec.rb +0 -36
  52. data/spec/unit/border/options/new_spec.rb +0 -12
  53. data/spec/unit/border/unicode/rendering_spec.rb +0 -61
  54. data/spec/unit/border_options/new_spec.rb +0 -18
  55. data/spec/unit/border_options/update_spec.rb +0 -16
  56. data/spec/unit/column_constraint/enforce_spec.rb +0 -68
  57. data/spec/unit/column_constraint/widths_spec.rb +0 -33
  58. data/spec/unit/columns/extract_widths_spec.rb +0 -41
  59. data/spec/unit/columns/total_width_spec.rb +0 -11
  60. data/spec/unit/columns/widths_from_spec.rb +0 -49
  61. data/spec/unit/data_spec.rb +0 -10
  62. data/spec/unit/each_spec.rb +0 -24
  63. data/spec/unit/each_with_index_spec.rb +0 -49
  64. data/spec/unit/empty_spec.rb +0 -21
  65. data/spec/unit/eql_spec.rb +0 -32
  66. data/spec/unit/field/equality_spec.rb +0 -49
  67. data/spec/unit/field/length_spec.rb +0 -33
  68. data/spec/unit/field/lines_spec.rb +0 -19
  69. data/spec/unit/field/new_spec.rb +0 -27
  70. data/spec/unit/field/width_spec.rb +0 -21
  71. data/spec/unit/filter_spec.rb +0 -20
  72. data/spec/unit/header/call_spec.rb +0 -28
  73. data/spec/unit/header/color_spec.rb +0 -17
  74. data/spec/unit/header/equality_spec.rb +0 -49
  75. data/spec/unit/header/height_spec.rb +0 -25
  76. data/spec/unit/header/new_spec.rb +0 -13
  77. data/spec/unit/header/set_spec.rb +0 -18
  78. data/spec/unit/header/to_ary_spec.rb +0 -12
  79. data/spec/unit/header_spec.rb +0 -11
  80. data/spec/unit/indentation/indent_spec.rb +0 -15
  81. data/spec/unit/new_spec.rb +0 -71
  82. data/spec/unit/operation/alignment/call_spec.rb +0 -37
  83. data/spec/unit/operation/escape/call_spec.rb +0 -13
  84. data/spec/unit/operation/filter/call_spec.rb +0 -14
  85. data/spec/unit/operation/truncation/call_spec.rb +0 -28
  86. data/spec/unit/operation/wrapped/call_spec.rb +0 -38
  87. data/spec/unit/operations/new_spec.rb +0 -28
  88. data/spec/unit/options/access_spec.rb +0 -12
  89. data/spec/unit/options_spec.rb +0 -23
  90. data/spec/unit/orientation_spec.rb +0 -143
  91. data/spec/unit/padding_spec.rb +0 -115
  92. data/spec/unit/properties_spec.rb +0 -23
  93. data/spec/unit/render_repeat_spec.rb +0 -39
  94. data/spec/unit/render_spec.rb +0 -61
  95. data/spec/unit/render_with_spec.rb +0 -104
  96. data/spec/unit/renderer/ascii/coloring_spec.rb +0 -83
  97. data/spec/unit/renderer/ascii/indentation_spec.rb +0 -39
  98. data/spec/unit/renderer/ascii/multiline_spec.rb +0 -99
  99. data/spec/unit/renderer/ascii/padding_spec.rb +0 -115
  100. data/spec/unit/renderer/ascii/render_spec.rb +0 -66
  101. data/spec/unit/renderer/ascii/resizing_spec.rb +0 -112
  102. data/spec/unit/renderer/ascii/separator_spec.rb +0 -38
  103. data/spec/unit/renderer/basic/alignment_spec.rb +0 -86
  104. data/spec/unit/renderer/basic/coloring_spec.rb +0 -59
  105. data/spec/unit/renderer/basic/extract_column_widths_spec.rb +0 -26
  106. data/spec/unit/renderer/basic/filter_spec.rb +0 -51
  107. data/spec/unit/renderer/basic/indentation_spec.rb +0 -46
  108. data/spec/unit/renderer/basic/multiline_spec.rb +0 -72
  109. data/spec/unit/renderer/basic/new_spec.rb +0 -24
  110. data/spec/unit/renderer/basic/options_spec.rb +0 -50
  111. data/spec/unit/renderer/basic/padding_spec.rb +0 -74
  112. data/spec/unit/renderer/basic/render_spec.rb +0 -55
  113. data/spec/unit/renderer/basic/resizing_spec.rb +0 -94
  114. data/spec/unit/renderer/basic/separator_spec.rb +0 -41
  115. data/spec/unit/renderer/basic/single_row_separator_spec.rb +0 -80
  116. data/spec/unit/renderer/basic/truncation_spec.rb +0 -33
  117. data/spec/unit/renderer/basic/wrapping_spec.rb +0 -38
  118. data/spec/unit/renderer/border_spec.rb +0 -102
  119. data/spec/unit/renderer/render_spec.rb +0 -34
  120. data/spec/unit/renderer/select_spec.rb +0 -20
  121. data/spec/unit/renderer/unicode/coloring_spec.rb +0 -68
  122. data/spec/unit/renderer/unicode/indentation_spec.rb +0 -39
  123. data/spec/unit/renderer/unicode/padding_spec.rb +0 -59
  124. data/spec/unit/renderer/unicode/render_spec.rb +0 -66
  125. data/spec/unit/renderer/unicode/separator_spec.rb +0 -36
  126. data/spec/unit/renderer_spec.rb +0 -17
  127. data/spec/unit/rotate_spec.rb +0 -84
  128. data/spec/unit/row/access_spec.rb +0 -23
  129. data/spec/unit/row/call_spec.rb +0 -43
  130. data/spec/unit/row/data_spec.rb +0 -24
  131. data/spec/unit/row/each_spec.rb +0 -29
  132. data/spec/unit/row/equality_spec.rb +0 -71
  133. data/spec/unit/row/height_spec.rb +0 -25
  134. data/spec/unit/row/new_spec.rb +0 -39
  135. data/spec/unit/row/to_ary_spec.rb +0 -12
  136. data/spec/unit/to_s_spec.rb +0 -56
  137. data/spec/unit/transformation/extract_tuples_spec.rb +0 -33
  138. data/spec/unit/utf_spec.rb +0 -31
  139. data/spec/unit/validatable/validate_options_spec.rb +0 -31
  140. data/spec/unit/validatable_spec.rb +0 -30
  141. data/tasks/console.rake +0 -11
  142. data/tasks/coverage.rake +0 -11
  143. data/tasks/spec.rake +0 -29
  144. data/tty-table.gemspec +0 -41
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Border, '#new' do
4
- let(:row) { [] }
5
-
6
- subject(:instance) { klass.new row, [0,0,0,0] }
7
-
8
- context 'when abstract' do
9
- let(:klass) { described_class }
10
-
11
- it { expect { instance }.to raise_error(NotImplementedError) }
12
- end
13
-
14
- context 'when concrete' do
15
- let(:klass) {
16
- Class.new do
17
- def initialize(row, padding); end
18
- end
19
- }
20
-
21
- it { expect { instance }.to_not raise_error() }
22
-
23
- it { is_expected.to be_instance_of klass }
24
- end
25
- end
@@ -1,128 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Border::Null, '#rendering' do
4
- let(:border) { nil }
5
-
6
- subject { described_class.new column_widths, border }
7
-
8
- context 'with empty row' do
9
- let(:row) { TTY::Table::Row.new([]) }
10
- let(:column_widths) { [] }
11
-
12
- it 'draws top line' do
13
- expect(subject.top_line).to be_nil
14
- end
15
-
16
- it 'draws middle line' do
17
- expect(subject.separator).to be_nil
18
- end
19
-
20
- it 'draw bottom line' do
21
- expect(subject.bottom_line).to be_nil
22
- end
23
-
24
- it 'draws row line' do
25
- expect(subject.row_line(row)).to eq('')
26
- end
27
- end
28
-
29
- context 'with row' do
30
- let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }
31
- let(:column_widths) { [2,2,2] }
32
-
33
- it 'draws top line' do
34
- expect(subject.top_line).to be_nil
35
- end
36
-
37
- it 'draw middle line' do
38
- expect(subject.separator).to be_nil
39
- end
40
-
41
- it 'draw bottom line' do
42
- expect(subject.bottom_line).to be_nil
43
- end
44
-
45
- it 'draws row line' do
46
- expect(subject.row_line(row)).to eq('a1 a2 a3')
47
- end
48
- end
49
-
50
- context 'with multiline row' do
51
- let(:column_widths) { [2,2,2] }
52
-
53
- context 'with mixed data' do
54
- let(:row) { TTY::Table::Row.new(["a1\nb1\nc1", 'a2', 'a3']) }
55
-
56
- it 'draws row line' do
57
- expect(subject.row_line(row)).to eq unindent(<<-EOS)
58
- a1 a2 a3
59
- b1
60
- c1
61
- EOS
62
- end
63
- end
64
-
65
- context 'with sparse data' do
66
- let(:row) { TTY::Table::Row.new(["a1\n\n", "\na2\n", "\n\na3"]) }
67
-
68
- it 'draws row line' do
69
- expect(subject.row_line(row)).to eq <<-EOS.chomp
70
- a1
71
- a2
72
- a3
73
- EOS
74
- end
75
- end
76
-
77
- context 'with empty data' do
78
- let(:row) { TTY::Table::Row.new(["\na1\n", "\na2\n", "\na3\n"]) }
79
-
80
- it 'draws row line' do
81
- expect(subject.row_line(row)).to eq <<-EOS.chomp
82
-
83
- a1 a2 a3
84
-
85
- EOS
86
- end
87
- end
88
- end
89
-
90
- context 'with border' do
91
- let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }
92
- let(:column_widths) { [2,2,2] }
93
- let(:border) { { :characters => {
94
- 'top' => '=',
95
- 'top_mid' => '=',
96
- 'top_left' => '=',
97
- 'top_right' => '=',
98
- 'bottom' => '=',
99
- 'bottom_mid' => '=',
100
- 'bottom_left' => '=',
101
- 'bottom_right' => '=',
102
- 'mid' => '=',
103
- 'mid_mid' => '=',
104
- 'mid_left' => '=',
105
- 'mid_right' => '=',
106
- 'left' => '=',
107
- 'center' => '=',
108
- 'right' => '='
109
- } } }
110
-
111
-
112
- it 'draws top line' do
113
- expect(subject.top_line).to eql '=========='
114
- end
115
-
116
- it 'draws separator line' do
117
- expect(subject.separator).to eql '=========='
118
- end
119
-
120
- it 'draws bottom line' do
121
- expect(subject.bottom_line).to eql '=========='
122
- end
123
-
124
- it 'draws row line' do
125
- expect(subject.row_line(row)).to eql '=a1=a2=a3='
126
- end
127
- end
128
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::BorderOptions, '#from' do
4
-
5
- subject(:options) { described_class.from object }
6
-
7
- context 'when empty hash' do
8
- let(:object) { {} }
9
-
10
- it { expect(options.style).to be_nil }
11
-
12
- it { expect(options.separator).to be_nil }
13
- end
14
-
15
- context 'when hash' do
16
- let(:object) { { style: :red, separator: :none } }
17
-
18
- it { expect(options).to be_kind_of(described_class) }
19
-
20
- it { expect(options.style).to eql :red }
21
-
22
- it { expect(options.separator).to eql :none }
23
-
24
- it { expect(options.characters).to eql({}) }
25
- end
26
-
27
- context 'when other BorderOptions' do
28
- let(:object) { described_class.new(nil, nil, :blue) }
29
-
30
- it { expect(options).to eql object }
31
-
32
- it { expect(options.characters).to eql({}) }
33
-
34
- it { expect(options.style).to eql :blue }
35
- end
36
- end # from
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::BorderOptions, '.new' do
4
-
5
- subject(:options) { described_class.new }
6
-
7
- it { expect(subject.characters).to eql({}) }
8
-
9
- it { expect(subject.separator).to be_nil }
10
-
11
- it { expect(subject.style).to be_nil }
12
- end # new
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Border::Unicode, '#rendering' do
4
-
5
- subject(:border) { described_class.new(column_widths) }
6
-
7
- context 'with empty row' do
8
- let(:row) { TTY::Table::Row.new([]) }
9
- let(:column_widths) { [] }
10
-
11
- it 'draws top line' do
12
- expect(border.top_line).to eq("┌┐")
13
- end
14
-
15
- it 'draws middle line' do
16
- expect(border.separator).to eq("├┤")
17
- end
18
-
19
- it 'draw bottom line' do
20
- expect(border.bottom_line).to eq("└┘")
21
- end
22
-
23
- it 'draws row line' do
24
- expect(border.row_line(row)).to eq("││")
25
- end
26
- end
27
-
28
- context 'with row' do
29
- let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }
30
- let(:column_widths) { [2,2,2] }
31
-
32
- it 'draws top line' do
33
- expect(border.top_line).to eq("┌──┬──┬──┐")
34
- end
35
-
36
- it 'draw middle line' do
37
- expect(border.separator).to eq("├──┼──┼──┤")
38
- end
39
-
40
- it 'draw bottom line' do
41
- expect(border.bottom_line).to eq("└──┴──┴──┘")
42
- end
43
-
44
- it 'draws row line' do
45
- expect(border.row_line(row)).to eq("│a1│a2│a3│")
46
- end
47
- end
48
-
49
- context 'with multiline row' do
50
- let(:row) { TTY::Table::Row.new(["a1\nb1\nc1", 'a2', 'a3']) }
51
- let(:column_widths) { [2,2,2] }
52
-
53
- it 'draws row line' do
54
- expect(border.row_line(row)).to eq unindent(<<-EOS)
55
- │a1│a2│a3│
56
- │b1│ │ │
57
- │c1│ │ │
58
- EOS
59
- end
60
- end
61
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::BorderOptions do
4
-
5
- subject { described_class.new(options) }
6
-
7
- context 'with characters' do
8
- let(:options) { {top: '**'} }
9
-
10
- it { expect(subject.characters).to eq({top:'**'}) }
11
- end
12
-
13
- context 'without characters' do
14
- let(:options) { nil }
15
-
16
- it { expect(subject.characters).to eq({}) }
17
- end
18
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::BorderOptions, '.update' do
4
-
5
- let(:object) { described_class.new }
6
-
7
- let(:params) { {characters: {top: '*'}, separator: '|', style: :red} }
8
-
9
- subject { object.update(params) }
10
-
11
- it 'sets properties from hash object' do
12
- expect(subject.characters).to eq({top: '*'})
13
- expect(subject.separator).to eq('|')
14
- expect(subject.style).to eq(:red)
15
- end
16
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::ColumnConstraint, '#enforce' do
4
- let(:header) { ['h1', 'h2', 'h3', 'h4'] }
5
- let(:rows) { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
6
- let(:table) { TTY::Table.new(header, rows) }
7
-
8
- subject(:columns) { described_class.new(table, renderer) }
9
-
10
- context 'with width contraint' do
11
- let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
12
- let(:options) { { width: 5 }}
13
-
14
- it 'raises error when table width is too small' do
15
- expect {
16
- columns.enforce
17
- }.to raise_error(TTY::Table::ResizeError)
18
- end
19
- end
20
-
21
- context 'with width contraint matching natural width' do
22
- let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
23
- let(:options) { { width: 11, resize: true }}
24
-
25
- it 'raises error when table width is too small' do
26
- allow(columns).to receive(:expand_column_widths)
27
- columns.enforce
28
- expect(columns).to have_received(:expand_column_widths)
29
- end
30
- end
31
-
32
- context 'with table larger than allowed width' do
33
- let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
34
-
35
- context 'with resize' do
36
- let(:options) { { width: 8, resize: true } }
37
-
38
- it 'calls shrink' do
39
- allow(columns).to receive(:shrink)
40
- columns.enforce
41
- expect(columns).to have_received(:shrink)
42
- end
43
- end
44
-
45
- context 'without resize' do
46
- let(:options) { { width: 8, resize: false }}
47
-
48
- it 'changes table orientation to vertical' do
49
- allow(Kernel).to receive(:warn)
50
- expect(renderer.column_widths).to eql([2,2,2,2])
51
- expect(table.orientation.name).to eql(:horizontal)
52
- column_widths = columns.enforce
53
- expect(column_widths).to eq([2,2])
54
- expect(table.orientation.name).to eql(:vertical)
55
- end
56
- end
57
- end
58
-
59
- context 'with table less than allowed width' do
60
- let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
61
- let(:options) { { width: 15 }}
62
-
63
- it "doesn't change original widths" do
64
- allow(Kernel).to receive(:warn)
65
- expect(renderer.column_widths).to eq([2,2,2,2])
66
- end
67
- end
68
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::ColumnConstraint, 'column widths' do
4
- let(:header) { ['h1', 'h2', 'h3', 'h4'] }
5
- let(:rows) { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
6
- let(:table) { TTY::Table.new(header, rows) }
7
-
8
- subject(:columns) { described_class.new(table, renderer) }
9
-
10
- context 'with basic renderer' do
11
- let(:renderer) { TTY::Table::Renderer::Basic.new(table) }
12
-
13
- it 'calculates columns natural width' do
14
- expect(columns.natural_width).to eq(11)
15
- end
16
-
17
- it 'calculates miminimum columns width' do
18
- expect(columns.minimum_width).to eq(7)
19
- end
20
- end
21
-
22
- context 'with ascii renderer' do
23
- let(:renderer) { TTY::Table::Renderer::ASCII.new(table) }
24
-
25
- it 'calculates columns natural width' do
26
- expect(columns.natural_width).to eq(13)
27
- end
28
-
29
- it 'calculates miminimum columns width' do
30
- expect(columns.minimum_width).to eq(9)
31
- end
32
- end
33
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Columns, '#extract_widths' do
4
- let(:color) { Pastel.new(enabled: true) }
5
-
6
- it 'extract widths' do
7
- header = ['h1', 'h2', 'h3']
8
- rows = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']]
9
- table = TTY::Table.new(header, rows)
10
- expect(described_class.extract_widths(table.data)).to eql([2,2,2])
11
- end
12
-
13
- it "extracts widths from utf" do
14
- header = ['h1', 'うなじ']
15
- rows = [['こんにちは', 'a2'], ['b1','選択']]
16
- table = TTY::Table.new(header, rows)
17
- expect(described_class.extract_widths(table.data)).to eql([10,6])
18
- end
19
-
20
- it "extracts widths from multiline text" do
21
- table = TTY::Table.new
22
- table << ["Multi\nLine\nContent", "Text\nthat\nwraps"]
23
- table << ["Some\nother\ntext", 'Simple']
24
- expect(described_class.extract_widths(table.data)).to eq([7,6])
25
- end
26
-
27
- it "extracts widths from multiline text" do
28
- table = TTY::Table.new
29
- table << ["Multi\\nLine\\nContent", "Text\\nthat\\nwraps"]
30
- table << ["Some\\nother\\ntext", 'Simple']
31
- expect(described_class.extract_widths(table.data)).to eq([20, 17])
32
- end
33
-
34
- it "extracts widths from ANSI text" do
35
- header = [color.green('h1'), 'h2']
36
- table = TTY::Table.new header: header
37
- table << [color.green.on_blue('a1'), 'a2']
38
- table << ['b1', color.red.on_yellow('b2')]
39
- expect(described_class.extract_widths(table.data)).to eq([2,2])
40
- end
41
- end