dashes 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +5 -5
  2. data/lib/dashes.rb +15 -3
  3. data/test/dashes_test.rb +81 -104
  4. metadata +2 -2
data/README.md CHANGED
@@ -1,19 +1,19 @@
1
1
  Description
2
2
  ===========
3
3
 
4
- Dashline formats data into a dashboard of charts/tables on the command line.
4
+ Dashes formats data into a dashboard of charts/tables on the command line.
5
5
 
6
6
  Installation
7
7
  ============
8
8
 
9
- $ gem install dashline
9
+ $ gem install dashes
10
10
 
11
11
  Usage
12
12
  =====
13
13
 
14
14
  Making a table:
15
15
 
16
- > table = Dashline::Table.new
16
+ > table = Dashes::Table.new
17
17
  > table.align :left, :right, :right # :center is available too
18
18
  > table.row 'Label', 'Num', 'Pct'
19
19
  > table.separator
@@ -36,7 +36,7 @@ Some display options for tables:
36
36
 
37
37
  Making a chart:
38
38
 
39
- > chart = Dashline::Chart.new
39
+ > chart = Dashes::Chart.new
40
40
  > chart.title 'Title'
41
41
  > chart.row 'First', 7
42
42
  > chart.row 'Second', 12
@@ -57,7 +57,7 @@ Some display options for charts:
57
57
 
58
58
  Combine tables and charts into a grid:
59
59
 
60
- > grid = Dashline::Grid.new
60
+ > grid = Dashes::Grid.new
61
61
  > grid.width(30) # 80 is the default , use `tput cols`.to_i for max width
62
62
  > grid.add table1
63
63
  > grid.add chart1
data/lib/dashes.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
 
3
3
  module Dashes
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
 
6
6
  def self.clean(str)
7
7
  str.to_s.
@@ -52,26 +52,32 @@ module Dashes
52
52
 
53
53
  def row(*data)
54
54
  @rows << data.map(&:to_s)
55
+ self
55
56
  end
56
57
 
57
58
  def separator
58
59
  @separators << @rows.length
60
+ self
59
61
  end
60
62
 
61
63
  def align(*alignments)
62
64
  @aligns = alignments
65
+ self
63
66
  end
64
67
 
65
68
  def width(width)
66
69
  @width = width
70
+ self
67
71
  end
68
72
 
69
73
  def max_width(max_width)
70
74
  @max_width = max_width
75
+ self
71
76
  end
72
77
 
73
78
  def spacing(*spacing)
74
79
  @spacing = spacing
80
+ self
75
81
  end
76
82
 
77
83
  def to_s
@@ -151,18 +157,22 @@ module Dashes
151
157
 
152
158
  def title(title)
153
159
  @title = title
160
+ self
154
161
  end
155
162
 
156
163
  def row(label, num)
157
164
  @rows << [label, num]
165
+ self
158
166
  end
159
167
 
160
168
  def width(width)
161
169
  @width = width
170
+ self
162
171
  end
163
172
 
164
173
  def max_width(max_width)
165
174
  @max_width = max_width
175
+ self
166
176
  end
167
177
 
168
178
  def to_s
@@ -218,12 +228,14 @@ module Dashes
218
228
  @width = 80
219
229
  end
220
230
 
221
- def add(node)
222
- @nodes << node
231
+ def add(*nodes)
232
+ @nodes += nodes
233
+ self
223
234
  end
224
235
 
225
236
  def width(width)
226
237
  @width = width
238
+ self
227
239
  end
228
240
 
229
241
  def to_s
data/test/dashes_test.rb CHANGED
@@ -23,15 +23,15 @@ class DashesTableTest < MiniTest::Unit::TestCase
23
23
  end
24
24
 
25
25
  def test_separators
26
- table = Dashes::Table.new
27
- table.separator
28
- table.separator
29
- table.row 'First', 'Second', 'Third'
30
- table.separator
31
- table.separator
32
- table.row 1, 2, 3
33
- table.separator
34
- table.separator
26
+ table = Dashes::Table.new.
27
+ separator.
28
+ separator.
29
+ row('First', 'Second', 'Third').
30
+ separator.
31
+ separator.
32
+ row(1, 2, 3).
33
+ separator.
34
+ separator
35
35
 
36
36
  assert_equal([5, 6, 5], table.send(:col_widths))
37
37
  assert_equal(26, table.total_width)
@@ -50,11 +50,11 @@ class DashesTableTest < MiniTest::Unit::TestCase
50
50
  end
51
51
 
52
52
  def test_alignment
53
- table = Dashes::Table.new
54
- table.align :left, :center, :right
55
- table.row 'First', 'Second', 'Third'
56
- table.separator
57
- table.row 1, 2, 3
53
+ table = Dashes::Table.new.
54
+ align(:left, :center, :right).
55
+ row('First', 'Second', 'Third').
56
+ separator.
57
+ row(1, 2, 3)
58
58
  assert_equal(
59
59
  "+-------+--------+-------+\n" +
60
60
  "| First | Second | Third |\n" +
@@ -65,9 +65,9 @@ class DashesTableTest < MiniTest::Unit::TestCase
65
65
  end
66
66
 
67
67
  def test_width
68
- table = Dashes::Table.new
69
- table.width 26
70
- table.row '1', '2', '3'
68
+ table = Dashes::Table.new.
69
+ width(26).
70
+ row('1', '2', '3')
71
71
  assert_equal(26, table.total_width)
72
72
  assert_equal(
73
73
  "+--------+-------+-------+\n" +
@@ -75,28 +75,28 @@ class DashesTableTest < MiniTest::Unit::TestCase
75
75
  "+--------+-------+-------+",
76
76
  table.to_s)
77
77
 
78
- table.spacing :min, :min, :max
78
+ table.spacing(:min, :min, :max)
79
79
  assert_equal(
80
80
  "+---+---+----------------+\n" +
81
81
  "| 1 | 2 | 3 |\n" +
82
82
  "+---+---+----------------+",
83
83
  table.to_s)
84
84
 
85
- table.spacing :max, :max, :min
85
+ table.spacing(:max, :max, :min)
86
86
  assert_equal(
87
87
  "+----------+---------+---+\n" +
88
88
  "| 1 | 2 | 3 |\n" +
89
89
  "+----------+---------+---+",
90
90
  table.to_s)
91
91
 
92
- table.spacing :min, :min, :min
92
+ table.spacing(:min, :min, :min)
93
93
  assert_equal(
94
94
  "+--------+-------+-------+\n" +
95
95
  "| 1 | 2 | 3 |\n" +
96
96
  "+--------+-------+-------+",
97
97
  table.to_s)
98
98
 
99
- table.spacing :max, :max, :max
99
+ table.spacing(:max, :max, :max)
100
100
  assert_equal(
101
101
  "+--------+-------+-------+\n" +
102
102
  "| 1 | 2 | 3 |\n" +
@@ -105,10 +105,10 @@ class DashesTableTest < MiniTest::Unit::TestCase
105
105
  end
106
106
 
107
107
  def test_max_width
108
- table = Dashes::Table.new
109
- table.max_width 26
110
- table.row 'First', 'Second', 'Third'
111
- table.row 1, 2, 3
108
+ table = Dashes::Table.new.
109
+ max_width(26).
110
+ row('First', 'Second', 'Third').
111
+ row(1, 2, 3)
112
112
  assert_equal(
113
113
  "+-------+--------+-------+\n" +
114
114
  "| First | Second | Third |\n" +
@@ -116,7 +116,7 @@ class DashesTableTest < MiniTest::Unit::TestCase
116
116
  "+-------+--------+-------+",
117
117
  table.to_s)
118
118
 
119
- table.max_width 14
119
+ table.max_width(14)
120
120
  assert_equal(
121
121
  "+---+----+---+\n" +
122
122
  "| F | Se | T |\n" +
@@ -124,7 +124,7 @@ class DashesTableTest < MiniTest::Unit::TestCase
124
124
  "+---+----+---+",
125
125
  table.to_s)
126
126
 
127
- table.width 26 # width takes priority
127
+ table.width(26) # width takes priority
128
128
  assert_equal(
129
129
  "+-------+--------+-------+\n" +
130
130
  "| First | Second | Third |\n" +
@@ -142,12 +142,12 @@ class DashesChartTest < MiniTest::Unit::TestCase
142
142
  end
143
143
 
144
144
  def test_basic_chart
145
- chart = Dashes::Chart.new
146
- chart.title 'Title'
147
- chart.row 'a', 20
148
- chart.row 'bb', 15
149
- chart.row 'ccc', 5
150
- chart.row 'dddd', 1
145
+ chart = Dashes::Chart.new.
146
+ title('Title').
147
+ row('a', 20).
148
+ row('bb', 15).
149
+ row('ccc', 5).
150
+ row('dddd', 1)
151
151
 
152
152
  assert_equal(
153
153
  "+---------------------------+\n" +
@@ -162,12 +162,12 @@ class DashesChartTest < MiniTest::Unit::TestCase
162
162
  end
163
163
 
164
164
  def test_normalized_width
165
- chart = Dashes::Chart.new
166
- chart.width(29)
167
- chart.row 'a', 40
168
- chart.row 'bb', 30
169
- chart.row 'ccc', 10
170
- chart.row 'dddd', 2
165
+ chart = Dashes::Chart.new.
166
+ width(29).
167
+ row('a', 40).
168
+ row('bb', 30).
169
+ row('ccc', 10).
170
+ row('dddd', 2)
171
171
  assert_equal(
172
172
  "+---------------------------+\n" +
173
173
  "| a ==================== |\n" +
@@ -179,12 +179,12 @@ class DashesChartTest < MiniTest::Unit::TestCase
179
179
  end
180
180
 
181
181
  def test_max_width
182
- chart = Dashes::Chart.new
183
- chart.max_width(100)
184
- chart.row 'a', 4
185
- chart.row 'bb', 3
186
- chart.row 'ccc', 2
187
- chart.row 'dddd', 1
182
+ chart = Dashes::Chart.new.
183
+ max_width(100).
184
+ row('a', 4).
185
+ row('bb', 3).
186
+ row('ccc', 2).
187
+ row('dddd', 1)
188
188
  assert_equal(
189
189
  "+-----------+\n" +
190
190
  "| a ==== |\n" +
@@ -194,12 +194,12 @@ class DashesChartTest < MiniTest::Unit::TestCase
194
194
  "+-----------+",
195
195
  chart.to_s)
196
196
 
197
- chart2 = Dashes::Chart.new
198
- chart2.max_width(13)
199
- chart2.row 'a', 8
200
- chart2.row 'bb', 6
201
- chart2.row 'ccc', 4
202
- chart2.row 'dddd', 2
197
+ chart2 = Dashes::Chart.new.
198
+ max_width(13).
199
+ row('a', 8).
200
+ row('bb', 6).
201
+ row('ccc', 4).
202
+ row('dddd', 2)
203
203
  assert_equal(
204
204
  "+-----------+\n" +
205
205
  "| a ==== |\n" +
@@ -226,29 +226,19 @@ class DashesGridTest < MiniTest::Unit::TestCase
226
226
  grid = Dashes::Grid.new
227
227
  assert_equal('', grid.to_s)
228
228
 
229
- grid.add Dashes::Table.new
230
- grid.add Dashes::Chart.new
229
+ grid.add(Dashes::Table.new, Dashes::Chart.new)
231
230
  assert_equal('', grid.to_s)
232
231
  end
233
232
 
234
233
  def test_basic_grid
235
- table = Dashes::Table.new
236
- table.row 'a', 'a', 'a'
237
- table.separator
238
- table.row 'a', 'a', 'a'
239
- table.separator
240
- table.row 'a', 'a', 'a'
241
- table2 = Dashes::Table.new
242
- table2.row 'b', 'b', 'b'
243
- table3 = Dashes::Table.new
244
- table3.row 'c', 'c', 'c'
245
-
246
- grid = Dashes::Grid.new
247
- grid.width 27
248
- grid.add table
249
- grid.add table2
250
- grid.add table3
251
-
234
+ table = Dashes::Table.new.
235
+ row('a', 'a', 'a').separator.
236
+ row('a', 'a', 'a').separator.
237
+ row('a', 'a', 'a')
238
+ table2 = Dashes::Table.new.row('b', 'b', 'b')
239
+ table3 = Dashes::Table.new.row('c', 'c', 'c')
240
+
241
+ grid = Dashes::Grid.new.width(27).add(table, table2, table3)
252
242
  assert_equal(
253
243
  "+---+---+---+ +---+---+---+\n" +
254
244
  "| a | a | a | | b | b | b |\n" +
@@ -259,17 +249,12 @@ class DashesGridTest < MiniTest::Unit::TestCase
259
249
  "+---+---+---+",
260
250
  grid.to_s)
261
251
 
262
- table4 = Dashes::Table.new
263
- table4.row 'a', 'a', 'a'
264
- table4.row 'a', 'a', 'a'
265
- table4.row 'a', 'a', 'a'
266
-
267
- grid2 = Dashes::Grid.new
268
- grid2.width 27
269
- grid2.add table4
270
- grid2.add table3
271
- grid2.add table2
252
+ table4 = Dashes::Table.new.
253
+ row('a', 'a', 'a').
254
+ row('a', 'a', 'a').
255
+ row('a', 'a', 'a')
272
256
 
257
+ grid2 = Dashes::Grid.new.width(27).add(table4, table3, table2)
273
258
  assert_equal(
274
259
  "+---+---+---+ +---+---+---+\n" +
275
260
  "| a | a | a | | c | c | c |\n" +
@@ -281,19 +266,17 @@ class DashesGridTest < MiniTest::Unit::TestCase
281
266
  end
282
267
 
283
268
  def test_mixed_grid
284
- table = Dashes::Table.new
285
- table.row 'a', 'a', 'a'
286
- table.row 'a', 'a', 'a'
287
- table.row 'a', 'a', 'a'
269
+ table = Dashes::Table.new.
270
+ row('a', 'a', 'a').
271
+ row('a', 'a', 'a').
272
+ row('a', 'a', 'a')
288
273
 
289
- chart = Dashes::Chart.new
290
- chart.row 'a', 5
291
- chart.row 'bb', 3
292
- chart.row 'ccc', 1
274
+ chart = Dashes::Chart.new.
275
+ row('a', 5).
276
+ row('bb', 3).
277
+ row('ccc', 1)
293
278
 
294
- grid = Dashes::Grid.new
295
- grid.add table
296
- grid.add chart
279
+ grid = Dashes::Grid.new.add(table, chart)
297
280
  assert_equal(
298
281
  "+---+---+---+ +-----------+\n" +
299
282
  "| a | a | a | | a ===== |\n" +
@@ -304,22 +287,16 @@ class DashesGridTest < MiniTest::Unit::TestCase
304
287
  end
305
288
 
306
289
  def test_alternating_grid
307
- short = Dashes::Table.new
308
- short.row 'a', 'a', 'a'
290
+ short = Dashes::Table.new.row('a', 'a', 'a')
309
291
 
310
- short2 = Dashes::Table.new
311
- short2.row 'b', 'b', 'b'
292
+ short2 = Dashes::Table.new.row('b', 'b', 'b')
312
293
 
313
- long = Dashes::Table.new
314
- long.row 'd', 'd', 'd'
315
- long.row 'd', 'd', 'd'
316
- long.row 'd', 'd', 'd'
294
+ long = Dashes::Table.new.
295
+ row('d', 'd', 'd').
296
+ row('d', 'd', 'd').
297
+ row('d', 'd', 'd')
317
298
 
318
- grid = Dashes::Grid.new
319
- grid.width(27)
320
- grid.add short
321
- grid.add long
322
- grid.add short2
299
+ grid = Dashes::Grid.new.width(27).add(short, long, short2)
323
300
  assert_equal(
324
301
  "+---+---+---+ +---+---+---+\n" +
325
302
  "| a | a | a | | d | d | d |\n" +
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dashes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-02 00:00:00.000000000 Z
12
+ date: 2013-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest