tty-table 0.7.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 (151) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +57 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +165 -94
  5. data/lib/tty-table.rb +1 -5
  6. data/lib/tty/table.rb +102 -42
  7. data/lib/tty/table/alignment_set.rb +3 -6
  8. data/lib/tty/table/border.rb +57 -68
  9. data/lib/tty/table/border/ascii.rb +17 -17
  10. data/lib/tty/table/border/null.rb +20 -22
  11. data/lib/tty/table/border/row_line.rb +4 -3
  12. data/lib/tty/table/border/unicode.rb +17 -17
  13. data/lib/tty/table/border_dsl.rb +28 -25
  14. data/lib/tty/table/border_options.rb +50 -25
  15. data/lib/tty/table/column_constraint.rb +29 -17
  16. data/lib/tty/table/{column_set.rb → columns.rb} +44 -69
  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 +43 -35
  20. data/lib/tty/table/header.rb +7 -5
  21. data/lib/tty/table/indentation.rb +16 -25
  22. data/lib/tty/table/operation/alignment.rb +10 -8
  23. data/lib/tty/table/operation/escape.rb +2 -3
  24. data/lib/tty/table/operation/filter.rb +1 -1
  25. data/lib/tty/table/operation/padding.rb +4 -12
  26. data/lib/tty/table/operation/truncation.rb +4 -4
  27. data/lib/tty/table/operation/wrapped.rb +4 -4
  28. data/lib/tty/table/operations.rb +4 -15
  29. data/lib/tty/table/options.rb +2 -4
  30. data/lib/tty/table/orientation.rb +5 -5
  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 +40 -35
  34. data/lib/tty/table/renderer/ascii.rb +4 -4
  35. data/lib/tty/table/renderer/basic.rb +85 -88
  36. data/lib/tty/table/renderer/unicode.rb +3 -3
  37. data/lib/tty/table/row.rb +10 -8
  38. data/lib/tty/table/transformation.rb +2 -2
  39. data/lib/tty/table/validatable.rb +25 -7
  40. data/lib/tty/table/version.rb +3 -3
  41. metadata +33 -283
  42. data/.gitignore +0 -14
  43. data/.rspec +0 -3
  44. data/.travis.yml +0 -24
  45. data/CODE_OF_CONDUCT.md +0 -49
  46. data/Gemfile +0 -18
  47. data/Rakefile +0 -8
  48. data/benchmarks/speed.rb +0 -41
  49. data/spec/spec_helper.rb +0 -50
  50. data/spec/unit/access_spec.rb +0 -86
  51. data/spec/unit/add_row_spec.rb +0 -28
  52. data/spec/unit/alignment_set/each_spec.rb +0 -17
  53. data/spec/unit/alignment_set/new_spec.rb +0 -27
  54. data/spec/unit/alignment_set/to_ary_spec.rb +0 -14
  55. data/spec/unit/alignment_spec.rb +0 -71
  56. data/spec/unit/border/ascii/rendering_spec.rb +0 -90
  57. data/spec/unit/border/new_spec.rb +0 -27
  58. data/spec/unit/border/null/rendering_spec.rb +0 -130
  59. data/spec/unit/border/options/from_spec.rb +0 -38
  60. data/spec/unit/border/options/new_spec.rb +0 -14
  61. data/spec/unit/border/unicode/rendering_spec.rb +0 -63
  62. data/spec/unit/border_options/new_spec.rb +0 -20
  63. data/spec/unit/border_options/update_spec.rb +0 -18
  64. data/spec/unit/column_constraint/enforce_spec.rb +0 -70
  65. data/spec/unit/column_constraint/widths_spec.rb +0 -35
  66. data/spec/unit/column_set/extract_widths_spec.rb +0 -48
  67. data/spec/unit/column_set/total_width_spec.rb +0 -15
  68. data/spec/unit/column_set/widths_from_spec.rb +0 -51
  69. data/spec/unit/data_spec.rb +0 -12
  70. data/spec/unit/each_spec.rb +0 -26
  71. data/spec/unit/each_with_index_spec.rb +0 -51
  72. data/spec/unit/empty_spec.rb +0 -23
  73. data/spec/unit/eql_spec.rb +0 -34
  74. data/spec/unit/field/equality_spec.rb +0 -51
  75. data/spec/unit/field/length_spec.rb +0 -35
  76. data/spec/unit/field/lines_spec.rb +0 -21
  77. data/spec/unit/field/new_spec.rb +0 -29
  78. data/spec/unit/field/width_spec.rb +0 -23
  79. data/spec/unit/filter_spec.rb +0 -22
  80. data/spec/unit/header/call_spec.rb +0 -30
  81. data/spec/unit/header/color_spec.rb +0 -19
  82. data/spec/unit/header/equality_spec.rb +0 -51
  83. data/spec/unit/header/height_spec.rb +0 -27
  84. data/spec/unit/header/new_spec.rb +0 -16
  85. data/spec/unit/header/set_spec.rb +0 -20
  86. data/spec/unit/header/to_ary_spec.rb +0 -14
  87. data/spec/unit/header_spec.rb +0 -13
  88. data/spec/unit/indentation/indent_spec.rb +0 -21
  89. data/spec/unit/new_spec.rb +0 -73
  90. data/spec/unit/operation/alignment/call_spec.rb +0 -39
  91. data/spec/unit/operation/escape/call_spec.rb +0 -15
  92. data/spec/unit/operation/filter/call_spec.rb +0 -16
  93. data/spec/unit/operation/truncation/call_spec.rb +0 -30
  94. data/spec/unit/operation/wrapped/call_spec.rb +0 -40
  95. data/spec/unit/operations/new_spec.rb +0 -30
  96. data/spec/unit/options/access_spec.rb +0 -14
  97. data/spec/unit/options_spec.rb +0 -25
  98. data/spec/unit/orientation_spec.rb +0 -145
  99. data/spec/unit/padding_spec.rb +0 -117
  100. data/spec/unit/properties_spec.rb +0 -25
  101. data/spec/unit/render_repeat_spec.rb +0 -42
  102. data/spec/unit/render_spec.rb +0 -63
  103. data/spec/unit/render_with_spec.rb +0 -106
  104. data/spec/unit/renderer/ascii/coloring_spec.rb +0 -70
  105. data/spec/unit/renderer/ascii/indentation_spec.rb +0 -41
  106. data/spec/unit/renderer/ascii/multiline_spec.rb +0 -101
  107. data/spec/unit/renderer/ascii/padding_spec.rb +0 -88
  108. data/spec/unit/renderer/ascii/render_spec.rb +0 -68
  109. data/spec/unit/renderer/ascii/resizing_spec.rb +0 -114
  110. data/spec/unit/renderer/ascii/separator_spec.rb +0 -28
  111. data/spec/unit/renderer/basic/alignment_spec.rb +0 -88
  112. data/spec/unit/renderer/basic/coloring_spec.rb +0 -61
  113. data/spec/unit/renderer/basic/extract_column_widths_spec.rb +0 -28
  114. data/spec/unit/renderer/basic/filter_spec.rb +0 -53
  115. data/spec/unit/renderer/basic/indentation_spec.rb +0 -48
  116. data/spec/unit/renderer/basic/multiline_spec.rb +0 -74
  117. data/spec/unit/renderer/basic/new_spec.rb +0 -26
  118. data/spec/unit/renderer/basic/options_spec.rb +0 -52
  119. data/spec/unit/renderer/basic/padding_spec.rb +0 -76
  120. data/spec/unit/renderer/basic/render_spec.rb +0 -57
  121. data/spec/unit/renderer/basic/resizing_spec.rb +0 -96
  122. data/spec/unit/renderer/basic/separator_spec.rb +0 -43
  123. data/spec/unit/renderer/basic/truncation_spec.rb +0 -35
  124. data/spec/unit/renderer/basic/wrapping_spec.rb +0 -40
  125. data/spec/unit/renderer/border_spec.rb +0 -104
  126. data/spec/unit/renderer/render_spec.rb +0 -36
  127. data/spec/unit/renderer/select_spec.rb +0 -22
  128. data/spec/unit/renderer/unicode/coloring_spec.rb +0 -70
  129. data/spec/unit/renderer/unicode/indentation_spec.rb +0 -41
  130. data/spec/unit/renderer/unicode/padding_spec.rb +0 -61
  131. data/spec/unit/renderer/unicode/render_spec.rb +0 -68
  132. data/spec/unit/renderer/unicode/separator_spec.rb +0 -26
  133. data/spec/unit/renderer_spec.rb +0 -19
  134. data/spec/unit/rotate_spec.rb +0 -86
  135. data/spec/unit/row/access_spec.rb +0 -25
  136. data/spec/unit/row/call_spec.rb +0 -45
  137. data/spec/unit/row/data_spec.rb +0 -26
  138. data/spec/unit/row/each_spec.rb +0 -31
  139. data/spec/unit/row/equality_spec.rb +0 -73
  140. data/spec/unit/row/height_spec.rb +0 -27
  141. data/spec/unit/row/new_spec.rb +0 -41
  142. data/spec/unit/row/to_ary_spec.rb +0 -14
  143. data/spec/unit/to_s_spec.rb +0 -56
  144. data/spec/unit/transformation/extract_tuples_spec.rb +0 -35
  145. data/spec/unit/utf_spec.rb +0 -33
  146. data/spec/unit/validatable/validate_options_spec.rb +0 -33
  147. data/spec/unit/validatable_spec.rb +0 -32
  148. data/tasks/console.rake +0 -10
  149. data/tasks/coverage.rake +0 -11
  150. data/tasks/spec.rake +0 -29
  151. data/tty-table.gemspec +0 -30
@@ -1,35 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::ColumnConstraint, 'column widths' do
6
- let(:header) { ['h1', 'h2', 'h3', 'h4'] }
7
- let(:rows) { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
8
- let(:table) { TTY::Table.new(header, rows) }
9
-
10
- subject(:columns) { described_class.new(table, renderer) }
11
-
12
- context 'with basic renderer' do
13
- let(:renderer) { TTY::Table::Renderer::Basic.new(table) }
14
-
15
- it 'calculates columns natural width' do
16
- expect(columns.natural_width).to eq(11)
17
- end
18
-
19
- it 'calculates miminimum columns width' do
20
- expect(columns.minimum_width).to eq(7)
21
- end
22
- end
23
-
24
- context 'with ascii renderer' do
25
- let(:renderer) { TTY::Table::Renderer::ASCII.new(table) }
26
-
27
- it 'calculates columns natural width' do
28
- expect(columns.natural_width).to eq(13)
29
- end
30
-
31
- it 'calculates miminimum columns width' do
32
- expect(columns.minimum_width).to eq(9)
33
- end
34
- end
35
- end
@@ -1,48 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::ColumnSet, '#extract_widths' do
6
- let(:color) { Pastel.new(enabled: true) }
7
-
8
- it 'extract widths' do
9
- header = ['h1', 'h2', 'h3']
10
- rows = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']]
11
- table = TTY::Table.new header, rows
12
- column_set = TTY::Table::ColumnSet.new(table)
13
- expect(column_set.extract_widths).to eql([2,2,2])
14
- end
15
-
16
- it "extracts widths from utf" do
17
- header = ['h1', 'うなじ']
18
- rows = [['こんにちは', 'a2'], ['b1','選択']]
19
- table = TTY::Table.new header, rows
20
- column_set = TTY::Table::ColumnSet.new(table)
21
- expect(column_set.extract_widths).to eql([10,6])
22
- end
23
-
24
- it "extracts widths from multiline text" do
25
- table = TTY::Table.new
26
- table << ["Multi\nLine\nContent", "Text\nthat\nwraps"]
27
- table << ["Some\nother\ntext", 'Simple']
28
- column_set = TTY::Table::ColumnSet.new(table)
29
- expect(column_set.extract_widths).to eq([7,6])
30
- end
31
-
32
- it "extracts widths from multiline text" do
33
- table = TTY::Table.new
34
- table << ["Multi\\nLine\\nContent", "Text\\nthat\\nwraps"]
35
- table << ["Some\\nother\\ntext", 'Simple']
36
- column_set = TTY::Table::ColumnSet.new(table)
37
- expect(column_set.extract_widths).to eq([20, 17])
38
- end
39
-
40
- it "extracts widths from ANSI text" do
41
- header = [color.green('h1'), 'h2']
42
- table = TTY::Table.new header: header
43
- table << [color.green.on_blue('a1'), 'a2']
44
- table << ['b1', color.red.on_yellow('b2')]
45
- column_set = TTY::Table::ColumnSet.new(table)
46
- expect(column_set.extract_widths).to eq([2,2])
47
- end
48
- end
@@ -1,15 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::ColumnSet, '#extract_widths!' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
- let(:table) { TTY::Table.new header, rows }
9
-
10
- subject { described_class.new table }
11
-
12
- it 'extract widths' do
13
- expect(subject.total_width).to eql(6)
14
- end
15
- end
@@ -1,51 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::ColumnSet, '#widths_from' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
- let(:table) { TTY::Table.new header, rows }
9
-
10
- subject { described_class.widths_from(table, column_widths) }
11
-
12
- context 'when empty array' do
13
- let(:column_widths) { [] }
14
-
15
- it 'raises an error' do
16
- expect { subject }.to raise_error(TTY::Table::InvalidArgument)
17
- end
18
- end
19
-
20
- context 'when invalid size array' do
21
- let(:column_widths) { [3,3] }
22
-
23
- it 'raises an error' do
24
- expect { subject }.to raise_error(TTY::Table::InvalidArgument)
25
- end
26
- end
27
-
28
- context 'when valid array' do
29
- let(:column_widths) { [3,3,3] }
30
-
31
- it 'converts into numbers' do
32
- expect(subject).to eql(column_widths)
33
- end
34
- end
35
-
36
- context 'when nil' do
37
- let(:column_widths) { nil }
38
-
39
- it 'extracts widths' do
40
- expect(subject).to eql([2,2,2])
41
- end
42
- end
43
-
44
- context 'when numeric' do
45
- let(:column_widths) { 5 }
46
-
47
- it 'generates widths' do
48
- expect(subject).to eql([5,5,5])
49
- end
50
- end
51
- end
@@ -1,12 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table, '.data' do
6
- it 'gets all table data' do
7
- header = ['h1', 'h2', 'h3']
8
- rows = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']]
9
- table = described_class.new header, rows
10
- expect(table.data).to eql([header] + rows)
11
- end
12
- end
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table, '#each' do
6
- let(:header) { ['Header1'] }
7
- let(:rows) { [['a1'], ['b1']] }
8
-
9
- subject(:table) { described_class.new(header, rows) }
10
-
11
- context 'with no block' do
12
- it { expect(table.each).to be_instance_of(to_enum.class) }
13
-
14
- it 'yields the expected values' do
15
- expect(table.each.to_a).to eql(table.to_a)
16
- end
17
- end
18
-
19
- context 'with block' do
20
- it 'yields each row' do
21
- yields = []
22
- table.each { |row| yields << row }
23
- expect(yields).to eql(table.to_a)
24
- end
25
- end
26
- end
@@ -1,51 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table, '.each_with_index' do
6
-
7
- context 'with no block' do
8
- it 'returns enumerable' do
9
- table = TTY::Table.new ['h1','h2'], [['a1','a2'],['b1','b2']]
10
- expect(table.each_with_index).to be_instance_of(to_enum.class)
11
- end
12
-
13
- it 'yields the expected values' do
14
- table = TTY::Table.new ['h1','h2'], [['a1','a2'],['b1','b2']]
15
- expect(table.each_with_index.to_a).to eql(table.to_a)
16
- end
17
- end
18
-
19
- context 'with block' do
20
- context 'without header' do
21
- it "yields rows with expected data" do
22
- yields = []
23
- table = TTY::Table.new [['a1','a2'],['b1','b2']]
24
- expected = [
25
- [['a1','a2'], 0],
26
- [['b1','b2'], 1]
27
- ]
28
- expect {
29
- table.each_with_index { |row, indx| yields << [row, indx] }
30
- }.to change { yields }.from([]).to(expected)
31
- end
32
- end
33
-
34
- context 'with header' do
35
- it "yields header and rows with expected data" do
36
- yields = []
37
- table = TTY::Table.new ['h1','h2'], [['a1','a2'],['b1','b2']]
38
-
39
- expected = [
40
- [['h1','h2'], 0],
41
- [['a1','a2'], 1],
42
- [['b1','b2'], 2]
43
- ]
44
-
45
- expect {
46
- table.each_with_index { |row, indx| yields << [row, indx] }
47
- }.to change { yields }.from( [] ).to( expected )
48
- end
49
- end
50
- end
51
- end
@@ -1,23 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table, '#empty?' do
6
- let(:header) { ['Header1', 'Header2'] }
7
- let(:object) { described_class.new header, rows }
8
-
9
- subject { object.empty? }
10
-
11
- context 'with rows containing no entries' do
12
- let(:rows) { [] }
13
-
14
- it { is_expected.to eq(true) }
15
- end
16
-
17
- context 'with rows containing an entry' do
18
- let(:rows) { [['a1']] }
19
-
20
- it { is_expected.to eq(false) }
21
- end
22
- end
23
-
@@ -1,34 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table, '#eql?' do
6
- let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
7
- let(:object) { described_class.new rows }
8
-
9
- subject { object.eql?(other) }
10
-
11
- describe '#inspect' do
12
- it { expect(object.inspect).to match(/#<TTY::Table/) }
13
- end
14
-
15
- context 'with the same object' do
16
- let(:other) { object }
17
-
18
- it { is_expected.to eql(true) }
19
-
20
- it 'is symmetric' do
21
- is_expected.to eql(other.eql?(object))
22
- end
23
- end
24
-
25
- context 'with an equivalent object' do
26
- let(:other) { object.dup }
27
-
28
- it { is_expected.to eql(true) }
29
-
30
- it 'is symmetric' do
31
- is_expected.to eql(other.eql?(object))
32
- end
33
- end
34
- end
@@ -1,51 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Field, '#==' do
6
- let(:value) { '1' }
7
- let(:object) { described_class.new(value) }
8
-
9
- subject { object == other }
10
-
11
- context 'with the same object' do
12
- let(:other) { object }
13
-
14
- it { is_expected.to eql(true) }
15
-
16
- it 'is symmetric' do
17
- is_expected.to eql(other == object)
18
- end
19
- end
20
-
21
- context 'with an equivalent object' do
22
- let(:other) { object.dup }
23
-
24
- it { is_expected.to eql(true) }
25
-
26
- it 'is symmetric' do
27
- is_expected.to eql(other == object)
28
- end
29
- end
30
-
31
- context 'with an equivalent object of subclass' do
32
- let(:other) { Class.new(described_class).new(value) }
33
-
34
- it { is_expected.to eq(true) }
35
-
36
- it 'is symmetric' do
37
- is_expected.not_to eql(other == object)
38
- end
39
- end
40
-
41
- context 'with an object having a different value' do
42
- let(:other_value) { '2' }
43
- let(:other) { described_class.new(other_value) }
44
-
45
- it { is_expected.to eql(false) }
46
-
47
- it 'is symmetric' do
48
- is_expected.to eql(other == object)
49
- end
50
- end
51
- end
@@ -1,35 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Field, '.length' do
6
- it "calculates length for nil string" do
7
- field = described_class.new(nil)
8
- expect(field.length).to eq(0)
9
- end
10
-
11
- it "calculates length for empty string" do
12
- field = described_class.new('')
13
- expect(field.length).to eq(0)
14
- end
15
-
16
- it "calculates maximum length for multiline string" do
17
- field = described_class.new("Multi\nLine\nContent")
18
- expect(field.length).to eq(7)
19
- end
20
-
21
- it "calculates length for unicode string" do
22
- field = described_class.new('こんにちは')
23
- expect(field.length).to eq(10)
24
- end
25
-
26
- it "calculates length for escaped string" do
27
- field = described_class.new("Multi\\nLine")
28
- expect(field.length).to eq(11)
29
- end
30
-
31
- it "calculates length for colored string" do
32
- field = described_class.new("\e[32;41mgreen on red\e[0m")
33
- expect(field.length).to eq(12)
34
- end
35
- end
@@ -1,21 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Field, '#lines' do
6
- let(:object) { described_class.new value }
7
-
8
- subject { object.lines }
9
-
10
- context 'with escaped value' do
11
- let(:value) { "Multi\nLine" }
12
-
13
- it { is_expected.to eql(["Multi", "Line"]) }
14
- end
15
-
16
- context 'with unescaped value' do
17
- let(:value) { "Multi\\nLine" }
18
-
19
- it { is_expected.to eql(["Multi\\nLine"]) }
20
- end
21
- end
@@ -1,29 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Field, '#new' do
6
- let(:object) { described_class }
7
-
8
- subject { object.new value }
9
-
10
- context 'with only value' do
11
- let(:value) { 'foo' }
12
-
13
- it { is_expected.to be_instance_of(object) }
14
-
15
- it { expect(subject.value).to eql(value) }
16
-
17
- it { expect(subject.height).to eql(1) }
18
- end
19
-
20
- context 'with hash value' do
21
- let(:value) { { :value => 'foo' } }
22
-
23
- it { is_expected.to be_instance_of(object) }
24
-
25
- it { expect(subject.value).to eql('foo') }
26
-
27
- it { expect(subject.height).to eql(1) }
28
- end
29
- end