tty 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/.travis.yml +0 -1
  2. data/README.md +141 -23
  3. data/benchmarks/table.rb +5 -0
  4. data/lib/tty/logger.rb +71 -0
  5. data/lib/tty/support/equatable.rb +6 -2
  6. data/lib/tty/system/which.rb +41 -0
  7. data/lib/tty/system.rb +8 -0
  8. data/lib/tty/table/border/ascii.rb +15 -16
  9. data/lib/tty/table/border/null.rb +9 -4
  10. data/lib/tty/table/border/unicode.rb +15 -16
  11. data/lib/tty/table/border.rb +69 -9
  12. data/lib/tty/table/border_dsl.rb +247 -0
  13. data/lib/tty/table/border_options.rb +52 -0
  14. data/lib/tty/table/field.rb +101 -0
  15. data/lib/tty/table/header.rb +115 -0
  16. data/lib/tty/table/operation/alignment_set.rb +14 -10
  17. data/lib/tty/table/operation/truncation.rb +19 -13
  18. data/lib/tty/table/operation/wrapped.rb +20 -9
  19. data/lib/tty/table/operations.rb +69 -0
  20. data/lib/tty/table/renderer/basic.rb +35 -26
  21. data/lib/tty/table/renderer.rb +13 -1
  22. data/lib/tty/table/row.rb +174 -0
  23. data/lib/tty/table.rb +96 -21
  24. data/lib/tty/text/truncation.rb +1 -1
  25. data/lib/tty/vector.rb +8 -7
  26. data/lib/tty/version.rb +1 -1
  27. data/lib/tty.rb +21 -0
  28. data/spec/tty/logger/new_spec.rb +36 -0
  29. data/spec/tty/logger/valid_level_spec.rb +33 -0
  30. data/spec/tty/system/platform_spec.rb +8 -0
  31. data/spec/tty/system/which_spec.rb +41 -0
  32. data/spec/tty/table/access_spec.rb +12 -1
  33. data/spec/tty/table/add_row_spec.rb +28 -0
  34. data/spec/tty/table/border/new_spec.rb +9 -4
  35. data/spec/tty/table/border/null/rendering_spec.rb +39 -1
  36. data/spec/tty/table/border/options/from_spec.rb +39 -0
  37. data/spec/tty/table/border/options/new_spec.rb +15 -0
  38. data/spec/tty/table/border/style_spec.rb +70 -0
  39. data/spec/tty/table/border_spec.rb +107 -0
  40. data/spec/tty/table/each_with_index_spec.rb +30 -0
  41. data/spec/tty/table/field/equality_spec.rb +51 -0
  42. data/spec/tty/table/field/new_spec.rb +29 -0
  43. data/spec/tty/table/field/width_spec.rb +21 -0
  44. data/spec/tty/table/header/call_spec.rb +30 -0
  45. data/spec/tty/table/header/new_spec.rb +25 -0
  46. data/spec/tty/table/header/set_spec.rb +15 -0
  47. data/spec/tty/table/header/to_ary_spec.rb +14 -0
  48. data/spec/tty/table/header_spec.rb +14 -0
  49. data/spec/tty/table/operation/alignment_set/align_rows_spec.rb +8 -1
  50. data/spec/tty/table/operation/truncation/call_spec.rb +27 -0
  51. data/spec/tty/table/operation/wrapped/call_spec.rb +27 -0
  52. data/spec/tty/table/operations/new_spec.rb +32 -0
  53. data/spec/tty/table/options_spec.rb +17 -9
  54. data/spec/tty/table/renderer/basic/alignment_spec.rb +76 -29
  55. data/spec/tty/table/renderer/basic/separator_spec.rb +99 -0
  56. data/spec/tty/table/renderer_spec.rb +7 -1
  57. data/spec/tty/table/renders_with_spec.rb +35 -28
  58. data/spec/tty/table/rotate_spec.rb +1 -0
  59. data/spec/tty/table/row/access_spec.rb +25 -0
  60. data/spec/tty/table/row/call_spec.rb +41 -0
  61. data/spec/tty/table/row/data_spec.rb +26 -0
  62. data/spec/tty/table/row/equality_spec.rb +73 -0
  63. data/spec/tty/table/row/new_spec.rb +41 -0
  64. data/spec/tty/table/row/to_ary_spec.rb +14 -0
  65. data/spec/tty/text/truncation/truncate_spec.rb +6 -0
  66. metadata +72 -10
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table::Row, '#call' do
6
+ let(:object) { described_class.new(data) }
7
+
8
+ subject { object.call(attribute) }
9
+
10
+ context 'when integer' do
11
+ let(:data) { ['a', 'b'] }
12
+
13
+ let(:attribute) { 1 }
14
+
15
+ it { should == '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 { should == 1 }
25
+ end
26
+
27
+ context 'when array access' do
28
+ let(:attribute) { 0 }
29
+
30
+ it { should == 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 { expect { subject }.to raise_error(TTY::UnknownAttributeError) }
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ 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 { should be_instance_of(Hash) }
15
+
16
+ it { should eql(0 => 'a') }
17
+ end
18
+
19
+ context 'with attributes' do
20
+ let(:header) { [:id] }
21
+
22
+ it { should be_instance_of(Hash) }
23
+
24
+ it { should eql(:id => 'a') }
25
+ end
26
+ end
@@ -0,0 +1,73 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ 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 { should be_true }
16
+
17
+ it 'is symmetric' do
18
+ should eql(other == object)
19
+ end
20
+ end
21
+
22
+ context 'with an equivalent object' do
23
+ let(:other) { object.dup }
24
+
25
+ it { should be_true }
26
+
27
+ it 'is symmetric' do
28
+ should 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 { should be_true }
36
+
37
+ it 'is symmetric' do
38
+ should 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 { should be_true }
47
+
48
+ it 'is symmetric' do
49
+ should 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 { should be_false }
58
+
59
+ it 'is symmetric' do
60
+ should 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 { should be_true }
68
+
69
+ it 'is symmetric' do
70
+ should eql(other == object)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ 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 { should be_instance_of(object) }
14
+
15
+ it { should be_empty }
16
+
17
+ its(:attributes) { should == [] }
18
+
19
+ its(:data) { should == { }}
20
+ end
21
+
22
+ context 'with Array argument' do
23
+ let(:data) { ['a'] }
24
+
25
+ it { should be_instance_of(object) }
26
+
27
+ its(:attributes) { should == [0] }
28
+
29
+ its(:to_hash) { should == {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
+ its(:attributes) { should == [:id] }
38
+
39
+ its(:to_hash) { should == {:id => 'a'} }
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ 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 { should be_instance_of(Array) }
12
+
13
+ it { should == data }
14
+ end
@@ -25,6 +25,12 @@ describe TTY::Text::Truncation, '#truncate' do
25
25
  it { should == text }
26
26
  end
27
27
 
28
+ context 'with equal length' do
29
+ let(:length) { text.length }
30
+
31
+ it { should == text }
32
+ end
33
+
28
34
  context 'with truncation' do
29
35
  let(:length) { 12 }
30
36
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-17 00:00:00.000000000 Z
12
+ date: 2013-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2152283780 !ruby/object:Gem::Requirement
16
+ requirement: &2152273080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152283780
24
+ version_requirements: *2152273080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2152283220 !ruby/object:Gem::Requirement
27
+ requirement: &2152272300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152283220
35
+ version_requirements: *2152272300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yard
38
- requirement: &2152282700 !ruby/object:Gem::Requirement
38
+ requirement: &2152271820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152282700
46
+ version_requirements: *2152271820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: benchmark_suite
49
- requirement: &2152273700 !ruby/object:Gem::Requirement
49
+ requirement: &2152269160 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2152273700
57
+ version_requirements: *2152269160
58
58
  description: Toolbox for developing CLI clients
59
59
  email:
60
60
  - ''
@@ -79,6 +79,7 @@ files:
79
79
  - lib/tty/coercer/float.rb
80
80
  - lib/tty/coercer/integer.rb
81
81
  - lib/tty/coercer/range.rb
82
+ - lib/tty/logger.rb
82
83
  - lib/tty/shell.rb
83
84
  - lib/tty/shell/question.rb
84
85
  - lib/tty/shell/question/modifier.rb
@@ -94,17 +95,23 @@ files:
94
95
  - lib/tty/support/unicode.rb
95
96
  - lib/tty/support/utils.rb
96
97
  - lib/tty/system.rb
98
+ - lib/tty/system/which.rb
97
99
  - lib/tty/table.rb
98
100
  - lib/tty/table/border.rb
99
101
  - lib/tty/table/border/ascii.rb
100
102
  - lib/tty/table/border/null.rb
101
103
  - lib/tty/table/border/unicode.rb
104
+ - lib/tty/table/border_dsl.rb
105
+ - lib/tty/table/border_options.rb
102
106
  - lib/tty/table/column_set.rb
103
107
  - lib/tty/table/error.rb
108
+ - lib/tty/table/field.rb
109
+ - lib/tty/table/header.rb
104
110
  - lib/tty/table/operation/alignment.rb
105
111
  - lib/tty/table/operation/alignment_set.rb
106
112
  - lib/tty/table/operation/truncation.rb
107
113
  - lib/tty/table/operation/wrapped.rb
114
+ - lib/tty/table/operations.rb
108
115
  - lib/tty/table/orientation.rb
109
116
  - lib/tty/table/orientation/horizontal.rb
110
117
  - lib/tty/table/orientation/vertical.rb
@@ -113,6 +120,7 @@ files:
113
120
  - lib/tty/table/renderer/basic.rb
114
121
  - lib/tty/table/renderer/color.rb
115
122
  - lib/tty/table/renderer/unicode.rb
123
+ - lib/tty/table/row.rb
116
124
  - lib/tty/table/validatable.rb
117
125
  - lib/tty/terminal.rb
118
126
  - lib/tty/terminal/color.rb
@@ -128,6 +136,8 @@ files:
128
136
  - spec/tty/coercer/float/coerce_spec.rb
129
137
  - spec/tty/coercer/integer/coerce_spec.rb
130
138
  - spec/tty/coercer/range/coerce_spec.rb
139
+ - spec/tty/logger/new_spec.rb
140
+ - spec/tty/logger/valid_level_spec.rb
131
141
  - spec/tty/shell/ask_spec.rb
132
142
  - spec/tty/shell/error_spec.rb
133
143
  - spec/tty/shell/print_table_spec.rb
@@ -163,15 +173,30 @@ files:
163
173
  - spec/tty/support/equatable_spec.rb
164
174
  - spec/tty/support/fixtures/classes.rb
165
175
  - spec/tty/system/platform_spec.rb
176
+ - spec/tty/system/which_spec.rb
166
177
  - spec/tty/table/access_spec.rb
178
+ - spec/tty/table/add_row_spec.rb
167
179
  - spec/tty/table/border/ascii/rendering_spec.rb
168
180
  - spec/tty/table/border/new_spec.rb
169
181
  - spec/tty/table/border/null/rendering_spec.rb
182
+ - spec/tty/table/border/options/from_spec.rb
183
+ - spec/tty/table/border/options/new_spec.rb
184
+ - spec/tty/table/border/style_spec.rb
170
185
  - spec/tty/table/border/unicode/rendering_spec.rb
186
+ - spec/tty/table/border_spec.rb
171
187
  - spec/tty/table/column_set/extract_widths_spec.rb
172
188
  - spec/tty/table/each_spec.rb
189
+ - spec/tty/table/each_with_index_spec.rb
173
190
  - spec/tty/table/empty_spec.rb
174
191
  - spec/tty/table/eql_spec.rb
192
+ - spec/tty/table/field/equality_spec.rb
193
+ - spec/tty/table/field/new_spec.rb
194
+ - spec/tty/table/field/width_spec.rb
195
+ - spec/tty/table/header/call_spec.rb
196
+ - spec/tty/table/header/new_spec.rb
197
+ - spec/tty/table/header/set_spec.rb
198
+ - spec/tty/table/header/to_ary_spec.rb
199
+ - spec/tty/table/header_spec.rb
175
200
  - spec/tty/table/initialize_spec.rb
176
201
  - spec/tty/table/operation/alignment/format_spec.rb
177
202
  - spec/tty/table/operation/alignment/new_spec.rb
@@ -179,8 +204,11 @@ files:
179
204
  - spec/tty/table/operation/alignment_set/each_spec.rb
180
205
  - spec/tty/table/operation/alignment_set/new_spec.rb
181
206
  - spec/tty/table/operation/alignment_set/to_ary_spec.rb
207
+ - spec/tty/table/operation/truncation/call_spec.rb
182
208
  - spec/tty/table/operation/truncation/truncate_spec.rb
209
+ - spec/tty/table/operation/wrapped/call_spec.rb
183
210
  - spec/tty/table/operation/wrapped/wrap_spec.rb
211
+ - spec/tty/table/operations/new_spec.rb
184
212
  - spec/tty/table/options_spec.rb
185
213
  - spec/tty/table/orientation_spec.rb
186
214
  - spec/tty/table/properties_spec.rb
@@ -188,11 +216,18 @@ files:
188
216
  - spec/tty/table/renderer/basic/extract_column_widths_spec.rb
189
217
  - spec/tty/table/renderer/basic/new_spec.rb
190
218
  - spec/tty/table/renderer/basic/render_spec.rb
219
+ - spec/tty/table/renderer/basic/separator_spec.rb
191
220
  - spec/tty/table/renderer/basic_spec.rb
192
221
  - spec/tty/table/renderer/pick_renderer_spec.rb
193
222
  - spec/tty/table/renderer_spec.rb
194
223
  - spec/tty/table/renders_with_spec.rb
195
224
  - spec/tty/table/rotate_spec.rb
225
+ - spec/tty/table/row/access_spec.rb
226
+ - spec/tty/table/row/call_spec.rb
227
+ - spec/tty/table/row/data_spec.rb
228
+ - spec/tty/table/row/equality_spec.rb
229
+ - spec/tty/table/row/new_spec.rb
230
+ - spec/tty/table/row/to_ary_spec.rb
196
231
  - spec/tty/table/to_s_spec.rb
197
232
  - spec/tty/table/validatable/validate_options_spec.rb
198
233
  - spec/tty/table/validatable_spec.rb
@@ -244,6 +279,8 @@ test_files:
244
279
  - spec/tty/coercer/float/coerce_spec.rb
245
280
  - spec/tty/coercer/integer/coerce_spec.rb
246
281
  - spec/tty/coercer/range/coerce_spec.rb
282
+ - spec/tty/logger/new_spec.rb
283
+ - spec/tty/logger/valid_level_spec.rb
247
284
  - spec/tty/shell/ask_spec.rb
248
285
  - spec/tty/shell/error_spec.rb
249
286
  - spec/tty/shell/print_table_spec.rb
@@ -279,15 +316,30 @@ test_files:
279
316
  - spec/tty/support/equatable_spec.rb
280
317
  - spec/tty/support/fixtures/classes.rb
281
318
  - spec/tty/system/platform_spec.rb
319
+ - spec/tty/system/which_spec.rb
282
320
  - spec/tty/table/access_spec.rb
321
+ - spec/tty/table/add_row_spec.rb
283
322
  - spec/tty/table/border/ascii/rendering_spec.rb
284
323
  - spec/tty/table/border/new_spec.rb
285
324
  - spec/tty/table/border/null/rendering_spec.rb
325
+ - spec/tty/table/border/options/from_spec.rb
326
+ - spec/tty/table/border/options/new_spec.rb
327
+ - spec/tty/table/border/style_spec.rb
286
328
  - spec/tty/table/border/unicode/rendering_spec.rb
329
+ - spec/tty/table/border_spec.rb
287
330
  - spec/tty/table/column_set/extract_widths_spec.rb
288
331
  - spec/tty/table/each_spec.rb
332
+ - spec/tty/table/each_with_index_spec.rb
289
333
  - spec/tty/table/empty_spec.rb
290
334
  - spec/tty/table/eql_spec.rb
335
+ - spec/tty/table/field/equality_spec.rb
336
+ - spec/tty/table/field/new_spec.rb
337
+ - spec/tty/table/field/width_spec.rb
338
+ - spec/tty/table/header/call_spec.rb
339
+ - spec/tty/table/header/new_spec.rb
340
+ - spec/tty/table/header/set_spec.rb
341
+ - spec/tty/table/header/to_ary_spec.rb
342
+ - spec/tty/table/header_spec.rb
291
343
  - spec/tty/table/initialize_spec.rb
292
344
  - spec/tty/table/operation/alignment/format_spec.rb
293
345
  - spec/tty/table/operation/alignment/new_spec.rb
@@ -295,8 +347,11 @@ test_files:
295
347
  - spec/tty/table/operation/alignment_set/each_spec.rb
296
348
  - spec/tty/table/operation/alignment_set/new_spec.rb
297
349
  - spec/tty/table/operation/alignment_set/to_ary_spec.rb
350
+ - spec/tty/table/operation/truncation/call_spec.rb
298
351
  - spec/tty/table/operation/truncation/truncate_spec.rb
352
+ - spec/tty/table/operation/wrapped/call_spec.rb
299
353
  - spec/tty/table/operation/wrapped/wrap_spec.rb
354
+ - spec/tty/table/operations/new_spec.rb
300
355
  - spec/tty/table/options_spec.rb
301
356
  - spec/tty/table/orientation_spec.rb
302
357
  - spec/tty/table/properties_spec.rb
@@ -304,11 +359,18 @@ test_files:
304
359
  - spec/tty/table/renderer/basic/extract_column_widths_spec.rb
305
360
  - spec/tty/table/renderer/basic/new_spec.rb
306
361
  - spec/tty/table/renderer/basic/render_spec.rb
362
+ - spec/tty/table/renderer/basic/separator_spec.rb
307
363
  - spec/tty/table/renderer/basic_spec.rb
308
364
  - spec/tty/table/renderer/pick_renderer_spec.rb
309
365
  - spec/tty/table/renderer_spec.rb
310
366
  - spec/tty/table/renders_with_spec.rb
311
367
  - spec/tty/table/rotate_spec.rb
368
+ - spec/tty/table/row/access_spec.rb
369
+ - spec/tty/table/row/call_spec.rb
370
+ - spec/tty/table/row/data_spec.rb
371
+ - spec/tty/table/row/equality_spec.rb
372
+ - spec/tty/table/row/new_spec.rb
373
+ - spec/tty/table/row/to_ary_spec.rb
312
374
  - spec/tty/table/to_s_spec.rb
313
375
  - spec/tty/table/validatable/validate_options_spec.rb
314
376
  - spec/tty/table/validatable_spec.rb