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,26 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Renderer::Unicode, 'with separator' 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
- let(:object) { described_class.new table }
11
-
12
- subject(:renderer) { object }
13
-
14
- it "renders each row" do
15
- renderer.border.separator= :each_row
16
- expect(renderer.render).to eq unindent(<<-EOS)
17
- ┌──┬──┬──┐
18
- │h1│h2│h3│
19
- ├──┼──┼──┤
20
- │a1│a2│a3│
21
- ├──┼──┼──┤
22
- │b1│b2│b3│
23
- └──┴──┴──┘
24
- EOS
25
- end
26
- end
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table, '#renderer' do
6
- let(:object) { described_class }
7
- let(:header) { ['h1', 'h2'] }
8
- let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
9
-
10
- subject(:table) { object.new(header, rows).renderer }
11
-
12
- it 'creates new renderer' do
13
- expect(subject).to be_kind_of(TTY::Table::Renderer::Basic)
14
- end
15
-
16
- it 'chains calls on renderer' do
17
- expect(subject.render).to eql("h1 h2\na1 a2\nb1 b2")
18
- end
19
- end
@@ -1,86 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table, '#rotate' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
-
9
- subject(:table) { described_class.new(header, rows) }
10
-
11
- before { table.orientation = :horizontal }
12
-
13
- context 'with default' do
14
- context 'without header' do
15
- let(:header) { nil }
16
-
17
- it 'preserves orientation' do
18
- expect(table.header).to be_nil
19
- expect(table.rotate.to_a).to eql rows
20
- end
21
- end
22
-
23
- context 'with header' do
24
- it 'preserves orientation' do
25
- expect(table.rotate.to_a).to eql [header] + rows
26
- end
27
- end
28
- end
29
-
30
- context 'with no header' do
31
- let(:header) { nil }
32
-
33
- it 'rotates the rows' do
34
- table.orientation = :vertical
35
- expect(table.rotate.to_a).to eql [
36
- ['1', 'a1'],
37
- ['2', 'a2'],
38
- ['3', 'a3'],
39
- ['1', 'b1'],
40
- ['2', 'b2'],
41
- ['3', 'b3'],
42
- ]
43
- expect(table.header).to be_nil
44
- end
45
-
46
- it 'rotates the rows back' do
47
- table.orientation = :vertical
48
- table.rotate
49
- table.orientation = :horizontal
50
- expect(table.rotate.to_a).to eql rows
51
- expect(table.header).to eql header
52
- end
53
-
54
- it 'roates the output' do
55
- expect(table.to_s).to eq("a1 a2 a3\nb1 b2 b3")
56
- table.orientation = :vertical
57
- table.rotate
58
- expect(table.to_s).to eq("1 a1\n2 a2\n3 a3\n1 b1\n2 b2\n3 b3")
59
- end
60
- end
61
-
62
- context 'with header' do
63
- it 'rotates the rows and merges header' do
64
- table.orientation = :vertical
65
- expect(table.rotate.to_a).to eql [
66
- ['h1', 'a1'],
67
- ['h2', 'a2'],
68
- ['h3', 'a3'],
69
- ['h1', 'b1'],
70
- ['h2', 'b2'],
71
- ['h3', 'b3'],
72
- ]
73
- expect(table.header).to be_empty
74
- end
75
-
76
- it 'rotates the rows and header back' do
77
- table.orientation = :vertical
78
- table.rotate
79
- expect(table.orientation).to be_a TTY::Table::Orientation::Vertical
80
-
81
- table.orientation = :horizontal
82
- expect(table.rotate.to_a).to eql [header] + rows
83
- expect(table.header).to eql header
84
- end
85
- end
86
- end
@@ -1,25 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Row, '#access' do
6
- let(:object) { described_class.new [] }
7
-
8
- before { object[attribute] = value}
9
-
10
- subject { object[attribute] }
11
-
12
- context 'when integer' do
13
- let(:attribute) { 0 }
14
- let(:value) { 1 }
15
-
16
- it { is_expected.to eq(1) }
17
- end
18
-
19
- context 'when symbol' do
20
- let(:attribute) { :id }
21
- let(:value) { 1 }
22
-
23
- it { is_expected.to eq(1) }
24
- end
25
- end
@@ -1,45 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Row, '#call' do
6
- let(:object) { described_class.new(data) }
7
-
8
- subject { object[attribute] }
9
-
10
- context 'when integer' do
11
- let(:data) { ['a', 'b'] }
12
-
13
- let(:attribute) { 1 }
14
-
15
- it { is_expected.to eql('b') }
16
- end
17
-
18
- context 'when symbol' do
19
- let(:data) { {:id => 1} }
20
-
21
- context 'when hash access' do
22
- let(:attribute) { :id }
23
-
24
- it { is_expected.to eql(1) }
25
- end
26
-
27
- context 'when array access' do
28
- let(:attribute) { 0 }
29
-
30
- it { is_expected.to eql(1) }
31
- end
32
- end
33
-
34
- context 'when unkown attribute' do
35
- let(:data) { {:id => 1} }
36
-
37
- let(:attribute) { :other }
38
-
39
- specify {
40
- expect {
41
- subject
42
- }.to raise_error(TTY::Table::UnknownAttributeError)
43
- }
44
- end
45
- end
@@ -1,26 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Row, '#data' do
6
- let(:object) { described_class.new data, header }
7
- let(:data) { ['a'] }
8
-
9
- subject { object.to_hash }
10
-
11
- context 'without attributes' do
12
- let(:header) { nil }
13
-
14
- it { is_expected.to be_instance_of(Hash) }
15
-
16
- it { is_expected.to eql(0 => 'a') }
17
- end
18
-
19
- context 'with attributes' do
20
- let(:header) { [:id] }
21
-
22
- it { is_expected.to be_instance_of(Hash) }
23
-
24
- it { is_expected.to eql(id: 'a') }
25
- end
26
- end
@@ -1,31 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Row, '#new' do
6
- let(:yields) { [] }
7
- let(:value) { 'a1' }
8
- let(:header) { ['Header1']}
9
- let(:row) { [ value ] }
10
- let(:object) { described_class.new row, header }
11
-
12
- context 'with block' do
13
- subject { object.each { |field| yields << field } }
14
-
15
- it 'yields only fields' do
16
- subject
17
- yields.each { |field| expect(field).to be_instance_of(value.class) }
18
- end
19
-
20
- it 'yields rows with expected attributes' do
21
- subject
22
- yields.each { |field| expect(field).to eql(value) }
23
- end
24
-
25
- it 'yields each row' do
26
- expect { subject }.to change { yields }.
27
- from( [] ).
28
- to( yields )
29
- end
30
- end
31
- end
@@ -1,73 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Row, '#==' do
6
- let(:attributes) { [:id] }
7
- let(:data) { ['1'] }
8
- let(:object) { described_class.new(data, attributes) }
9
-
10
- subject { object == other }
11
-
12
- context 'with the same object' do
13
- let(:other) { object }
14
-
15
- it { is_expected.to eql(true) }
16
-
17
- it 'is symmetric' do
18
- is_expected.to eql(other == object)
19
- end
20
- end
21
-
22
- context 'with an equivalent object' do
23
- let(:other) { object.dup }
24
-
25
- it { is_expected.to eql(true) }
26
-
27
- it 'is symmetric' do
28
- is_expected.to eql(other == object)
29
- end
30
- end
31
-
32
- context 'with an equivalent object of subclass' do
33
- let(:other) { Class.new(described_class).new(data, attributes: attributes) }
34
-
35
- it { is_expected.to eql(true) }
36
-
37
- it 'is symmetric' do
38
- is_expected.to eql(other == object)
39
- end
40
- end
41
-
42
- context 'with an object having a different attributes' do
43
- let(:other_attributes) { [:text] }
44
- let(:other) { described_class.new(data, attributes: other_attributes) }
45
-
46
- it { is_expected.to eql(true) }
47
-
48
- it 'is symmetric' do
49
- is_expected.to eql(other == object)
50
- end
51
- end
52
-
53
- context 'with an object having a different attributes' do
54
- let(:other_data) { [2] }
55
- let(:other) { described_class.new(other_data, attributes: attributes) }
56
-
57
- it { is_expected.to eql(false) }
58
-
59
- it 'is symmetric' do
60
- is_expected.to eql(other == object)
61
- end
62
- end
63
-
64
- context 'with an equivalent object responding to_ary' do
65
- let(:other) { data }
66
-
67
- it { is_expected.to eql(true) }
68
-
69
- it 'is symmetric' do
70
- is_expected.to eql(other == object)
71
- end
72
- end
73
- end
@@ -1,27 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Row, '#height' do
6
- let(:object) { described_class.new row }
7
-
8
- subject { object.height }
9
-
10
- context 'single row' do
11
- let(:row) { ['a1', 'b1'] }
12
-
13
- it { expect(subject).to eql(1) }
14
- end
15
-
16
- context 'non escaped multiline' do
17
- let(:row) { ["a1\na2\na3", 'b1'] }
18
-
19
- it { expect(subject).to eql(3)}
20
- end
21
-
22
- context 'escaped multiline' do
23
- let(:row) { ["a1\\na2\\na3", 'b1'] }
24
-
25
- it { expect(subject).to eql(1) }
26
- end
27
- end
@@ -1,41 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Row, '#new' do
6
- let(:object) { described_class }
7
-
8
- subject { object.new data }
9
-
10
- context 'with no arguments' do
11
- let(:data) { [] }
12
-
13
- it { is_expected.to be_instance_of(object) }
14
-
15
- it { is_expected.to be_empty }
16
-
17
- it { expect(subject.attributes).to eq([]) }
18
-
19
- it { expect(subject.data).to eq({}) }
20
- end
21
-
22
- context 'with Array argument' do
23
- let(:data) { ['a'] }
24
-
25
- it { is_expected.to be_instance_of(object) }
26
-
27
- it { expect(subject.attributes).to eq([0]) }
28
-
29
- it { expect(subject.to_hash).to eq({0 => "a"}) }
30
- end
31
-
32
- context 'with Hash argument' do
33
- let(:data) { {id: 'a'} }
34
-
35
- it { should be_instance_of(object) }
36
-
37
- it { expect(subject.attributes).to eq([:id]) }
38
-
39
- it { expect(subject.to_hash).to eq({:id => 'a'}) }
40
- end
41
- end
@@ -1,14 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table::Row, '#to_ary' do
6
- let(:object) { described_class.new data }
7
- let(:data) { ['a', 'b'] }
8
-
9
- subject { object.to_ary }
10
-
11
- it { is_expected.to be_instance_of(Array) }
12
-
13
- it { is_expected.to eq(data) }
14
- end
@@ -1,56 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Table, '#to_s' do
6
- let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
-
9
- subject(:table) { described_class.new(header, rows) }
10
-
11
- context 'without renderer' do
12
- it 'displayes basic table' do
13
- expect(table.render(:basic)).to eq unindent(<<-EOS)
14
- h1 h2 h3
15
- a1 a2 a3
16
- b1 b2 b3
17
- EOS
18
- end
19
- end
20
-
21
- context 'without border' do
22
- it 'displays table' do
23
- expect(table.to_s).to eq unindent(<<-EOS)
24
- h1 h2 h3
25
- a1 a2 a3
26
- b1 b2 b3
27
- EOS
28
- end
29
- end
30
-
31
- context 'with ascii border' do
32
- it 'displays table' do
33
- expect(table.render(:ascii)).to eq unindent(<<-EOS)
34
- +--+--+--+
35
- |h1|h2|h3|
36
- +--+--+--+
37
- |a1|a2|a3|
38
- |b1|b2|b3|
39
- +--+--+--+
40
- EOS
41
- end
42
- end
43
-
44
- context 'with unicode border' do
45
- it 'displays table' do
46
- expect(table.render(:unicode)).to eq unindent(<<-EOS)
47
- ┌──┬──┬──┐
48
- │h1│h2│h3│
49
- ├──┼──┼──┤
50
- │a1│a2│a3│
51
- │b1│b2│b3│
52
- └──┴──┴──┘
53
- EOS
54
- end
55
- end
56
- end # to_s