tty-table 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
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,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Columns, '#extract_widths!' do
4
- let(:header) { ['h1', 'h2', 'h3'] }
5
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
6
-
7
- it 'extract widths' do
8
- table = TTY::Table.new(header, rows)
9
- expect(described_class.total_width(table.data)).to eql(6)
10
- end
11
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Columns, '#widths_from' do
4
- let(:header) { ['h1', 'h2', 'h3'] }
5
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
6
- let(:table) { TTY::Table.new header, rows }
7
-
8
- subject { described_class.widths_from(table, column_widths) }
9
-
10
- context 'when empty array' do
11
- let(:column_widths) { [] }
12
-
13
- it 'raises an error' do
14
- expect { subject }.to raise_error(TTY::Table::InvalidArgument)
15
- end
16
- end
17
-
18
- context 'when invalid size array' do
19
- let(:column_widths) { [3,3] }
20
-
21
- it 'raises an error' do
22
- expect { subject }.to raise_error(TTY::Table::InvalidArgument)
23
- end
24
- end
25
-
26
- context 'when valid array' do
27
- let(:column_widths) { [3,3,3] }
28
-
29
- it 'converts into numbers' do
30
- expect(subject).to eql(column_widths)
31
- end
32
- end
33
-
34
- context 'when nil' do
35
- let(:column_widths) { nil }
36
-
37
- it 'extracts widths' do
38
- expect(subject).to eql([2,2,2])
39
- end
40
- end
41
-
42
- context 'when numeric' do
43
- let(:column_widths) { 5 }
44
-
45
- it 'generates widths' do
46
- expect(subject).to eql([5,5,5])
47
- end
48
- end
49
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table, '.data' do
4
- it 'gets all table data' do
5
- header = ['h1', 'h2', 'h3']
6
- rows = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']]
7
- table = described_class.new header, rows
8
- expect(table.data).to eql([header] + rows)
9
- end
10
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table, '#each' do
4
- let(:header) { ['Header1'] }
5
- let(:rows) { [['a1'], ['b1']] }
6
-
7
- subject(:table) { described_class.new(header, rows) }
8
-
9
- context 'with no block' do
10
- it { expect(table.each).to be_instance_of(to_enum.class) }
11
-
12
- it 'yields the expected values' do
13
- expect(table.each.to_a).to eql(table.to_a)
14
- end
15
- end
16
-
17
- context 'with block' do
18
- it 'yields each row' do
19
- yields = []
20
- table.each { |row| yields << row }
21
- expect(yields).to eql(table.to_a)
22
- end
23
- end
24
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table, '.each_with_index' do
4
-
5
- context 'with no block' do
6
- it 'returns enumerable' do
7
- table = TTY::Table.new ['h1','h2'], [['a1','a2'],['b1','b2']]
8
- expect(table.each_with_index).to be_instance_of(to_enum.class)
9
- end
10
-
11
- it 'yields the expected values' do
12
- table = TTY::Table.new ['h1','h2'], [['a1','a2'],['b1','b2']]
13
- expect(table.each_with_index.to_a).to eql(table.to_a)
14
- end
15
- end
16
-
17
- context 'with block' do
18
- context 'without header' do
19
- it "yields rows with expected data" do
20
- yields = []
21
- table = TTY::Table.new [['a1','a2'],['b1','b2']]
22
- expected = [
23
- [['a1','a2'], 0],
24
- [['b1','b2'], 1]
25
- ]
26
- expect {
27
- table.each_with_index { |row, indx| yields << [row, indx] }
28
- }.to change { yields }.from([]).to(expected)
29
- end
30
- end
31
-
32
- context 'with header' do
33
- it "yields header and rows with expected data" do
34
- yields = []
35
- table = TTY::Table.new ['h1','h2'], [['a1','a2'],['b1','b2']]
36
-
37
- expected = [
38
- [['h1','h2'], 0],
39
- [['a1','a2'], 1],
40
- [['b1','b2'], 2]
41
- ]
42
-
43
- expect {
44
- table.each_with_index { |row, indx| yields << [row, indx] }
45
- }.to change { yields }.from( [] ).to( expected )
46
- end
47
- end
48
- end
49
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table, '#empty?' do
4
- let(:header) { ['Header1', 'Header2'] }
5
- let(:object) { described_class.new header, rows }
6
-
7
- subject { object.empty? }
8
-
9
- context 'with rows containing no entries' do
10
- let(:rows) { [] }
11
-
12
- it { is_expected.to eq(true) }
13
- end
14
-
15
- context 'with rows containing an entry' do
16
- let(:rows) { [['a1']] }
17
-
18
- it { is_expected.to eq(false) }
19
- end
20
- end
21
-
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table, '#eql?' do
4
- let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
5
- let(:object) { described_class.new rows }
6
-
7
- subject { object.eql?(other) }
8
-
9
- describe '#inspect' do
10
- it { expect(object.inspect).to match(/#<TTY::Table/) }
11
- end
12
-
13
- context 'with the same object' do
14
- let(:other) { object }
15
-
16
- it { is_expected.to eql(true) }
17
-
18
- it 'is symmetric' do
19
- is_expected.to eql(other.eql?(object))
20
- end
21
- end
22
-
23
- context 'with an equivalent object' do
24
- let(:other) { object.dup }
25
-
26
- it { is_expected.to eql(true) }
27
-
28
- it 'is symmetric' do
29
- is_expected.to eql(other.eql?(object))
30
- end
31
- end
32
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Field, '#==' do
4
- let(:value) { '1' }
5
- let(:object) { described_class.new(value) }
6
-
7
- subject { object == other }
8
-
9
- context 'with the same object' do
10
- let(:other) { object }
11
-
12
- it { is_expected.to eql(true) }
13
-
14
- it 'is symmetric' do
15
- is_expected.to eql(other == object)
16
- end
17
- end
18
-
19
- context 'with an equivalent object' do
20
- let(:other) { object.dup }
21
-
22
- it { is_expected.to eql(true) }
23
-
24
- it 'is symmetric' do
25
- is_expected.to eql(other == object)
26
- end
27
- end
28
-
29
- context 'with an equivalent object of subclass' do
30
- let(:other) { Class.new(described_class).new(value) }
31
-
32
- it { is_expected.to eq(true) }
33
-
34
- it 'is symmetric' do
35
- is_expected.not_to eql(other == object)
36
- end
37
- end
38
-
39
- context 'with an object having a different value' do
40
- let(:other_value) { '2' }
41
- let(:other) { described_class.new(other_value) }
42
-
43
- it { is_expected.to eql(false) }
44
-
45
- it 'is symmetric' do
46
- is_expected.to eql(other == object)
47
- end
48
- end
49
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Field, '.length' do
4
- it "calculates length for nil string" do
5
- field = described_class.new(nil)
6
- expect(field.length).to eq(0)
7
- end
8
-
9
- it "calculates length for empty string" do
10
- field = described_class.new('')
11
- expect(field.length).to eq(0)
12
- end
13
-
14
- it "calculates maximum length for multiline string" do
15
- field = described_class.new("Multi\nLine\nContent")
16
- expect(field.length).to eq(7)
17
- end
18
-
19
- it "calculates length for unicode string" do
20
- field = described_class.new('こんにちは')
21
- expect(field.length).to eq(10)
22
- end
23
-
24
- it "calculates length for escaped string" do
25
- field = described_class.new("Multi\\nLine")
26
- expect(field.length).to eq(11)
27
- end
28
-
29
- it "calculates length for colored string" do
30
- field = described_class.new("\e[32;41mgreen on red\e[0m")
31
- expect(field.length).to eq(12)
32
- end
33
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Field, '#lines' do
4
- let(:object) { described_class.new value }
5
-
6
- subject { object.lines }
7
-
8
- context 'with escaped value' do
9
- let(:value) { "Multi\nLine" }
10
-
11
- it { is_expected.to eql(["Multi", "Line"]) }
12
- end
13
-
14
- context 'with unescaped value' do
15
- let(:value) { "Multi\\nLine" }
16
-
17
- it { is_expected.to eql(["Multi\\nLine"]) }
18
- end
19
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Field, '#new' do
4
- let(:object) { described_class }
5
-
6
- subject { object.new value }
7
-
8
- context 'with only value' do
9
- let(:value) { 'foo' }
10
-
11
- it { is_expected.to be_instance_of(object) }
12
-
13
- it { expect(subject.value).to eql(value) }
14
-
15
- it { expect(subject.height).to eql(1) }
16
- end
17
-
18
- context 'with hash value' do
19
- let(:value) { { :value => 'foo' } }
20
-
21
- it { is_expected.to be_instance_of(object) }
22
-
23
- it { expect(subject.value).to eql('foo') }
24
-
25
- it { expect(subject.height).to eql(1) }
26
- end
27
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Field, '#width' do
4
- let(:object) { described_class }
5
-
6
- let(:instance) { object.new(value) }
7
-
8
- subject { instance.width }
9
-
10
- context 'with only value' do
11
- let(:value) { 'foo' }
12
-
13
- it { is_expected.to eql(3) }
14
- end
15
-
16
- context 'with hash value' do
17
- let(:value) { "foo\nbaar" }
18
-
19
- it { is_expected.to eql(7) }
20
- end
21
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table, '#filter' do
4
- let(:header) { ['h1', 'h2', 'h3'] }
5
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
6
-
7
- subject(:table) { described_class.new(header, rows) }
8
-
9
- it 'filters fields' do
10
- expect(table.render do |renderer|
11
- renderer.filter = proc do |val, row, col|
12
- (col == 1 && row > 0) ? val.capitalize : val
13
- end
14
- end).to eq unindent(<<-EOS)
15
- h1 h2 h3
16
- a1 A2 a3
17
- b1 B2 b3
18
- EOS
19
- end
20
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Header, '#call' do
4
- let(:object) { described_class.new(attributes) }
5
- let(:attributes) { [:id, :name, :age] }
6
-
7
- subject { object[attribute] }
8
-
9
- context 'with a known attribute' do
10
- context 'when symbol' do
11
- let(:attribute) { :age }
12
-
13
- it { is_expected.to eq(2) }
14
- end
15
-
16
- context 'when integer' do
17
- let(:attribute) { 1 }
18
-
19
- it { is_expected.to eq(:name) }
20
- end
21
- end
22
-
23
- context 'with an unknown attribute' do
24
- let(:attribute) { :mine }
25
-
26
- it { expect { subject }.to raise_error(TTY::Table::UnknownAttributeError, "the header 'mine' is unknown")}
27
- end
28
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Header, 'color' do
4
-
5
- context 'when default' do
6
-
7
- end
8
-
9
- context 'when ascii' do
10
- let(:renderer) { :ascii }
11
- let(:red) { "\e[31m" }
12
- let(:clear) { "\e[0m" }
13
-
14
- xit 'renders header background in color' do
15
- end
16
- end
17
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Table::Header, '#==' do
4
- let(:attributes) { [:id, :name] }
5
- let(:object) { described_class.new(attributes) }
6
-
7
- subject { object == other }
8
-
9
- context 'with the same object' do
10
- let(:other) { object }
11
-
12
- it { is_expected.to eql(true) }
13
-
14
- it 'is symmetric' do
15
- is_expected.to eql(other == object)
16
- end
17
- end
18
-
19
- context 'with an equivalent object' do
20
- let(:other) { object.dup }
21
-
22
- it { is_expected.to eql(true) }
23
-
24
- it 'is symmetric' do
25
- is_expected.to eql(other == object)
26
- end
27
- end
28
-
29
- context 'with an equivalent object of subclass' do
30
- let(:other) { Class.new(described_class).new(attributes) }
31
-
32
- it { is_expected.to eql(true) }
33
-
34
- it 'is symmetric' do
35
- is_expected.to eql(other == object)
36
- end
37
- end
38
-
39
- context 'with an object having different attributes' do
40
- let(:other_attributes) { [:text] }
41
- let(:other) { described_class.new(other_attributes) }
42
-
43
- it { is_expected.to eql(false) }
44
-
45
- it 'is symmetric' do
46
- is_expected.to eql(other == object)
47
- end
48
- end
49
- end