collimator 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +15 -5
- data/Rakefile +0 -8
- data/collimator.gemspec +1 -1
- data/examples/bar_graph.rb +20 -0
- data/lib/collimator.rb +6 -577
- data/lib/collimator/bar_graph.rb +70 -0
- data/lib/collimator/exceptions.rb +4 -0
- data/lib/collimator/progress_bar.rb +62 -0
- data/lib/collimator/spinner.rb +32 -0
- data/lib/collimator/table.rb +484 -0
- data/lib/collimator/version.rb +1 -1
- data/test/bar_graph_test.rb +66 -0
- data/test/progressbar_test.rb +2 -7
- data/test/spinner_test.rb +14 -12
- data/test/table_test.rb +2 -12
- data/test/test_helper.rb +22 -9
- metadata +56 -82
data/lib/collimator/version.rb
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class TestBarGraph < Minitest::Test
|
4
|
+
def setup
|
5
|
+
BarGraph.clear_all
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_bar_graph__data_set
|
9
|
+
assert_equal [], BarGraph.data, 'should start with an empty data set'
|
10
|
+
|
11
|
+
BarGraph.data = [ {:value => 10, :name => 'value 1'}, {:name => 'value 2', :value => 4} ]
|
12
|
+
|
13
|
+
assert_equal [ {:value => 10, :name => 'value 1'}, {:name => 'value 2', :value => 4} ], BarGraph.data
|
14
|
+
|
15
|
+
BarGraph.data = {:name => 'extra', :value => 101}
|
16
|
+
|
17
|
+
assert_equal [ {:value => 10, :name => 'value 1'}, {:name => 'value 2', :value => 4}, {:name => 'extra', :value => 101} ], BarGraph.data
|
18
|
+
|
19
|
+
BarGraph.clear_data
|
20
|
+
|
21
|
+
assert_equal [], BarGraph.data, 'should start with an empty data set'
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_bar_graph__simple_plot
|
25
|
+
|
26
|
+
data = []
|
27
|
+
data << {:name => 'USA', :value => 10}
|
28
|
+
data << {:name => 'Holland', :value => 14}
|
29
|
+
data << {:name => 'Spain', :value => 7}
|
30
|
+
data << {:name => 'Germany', :value => 12}
|
31
|
+
|
32
|
+
BarGraph.data = data
|
33
|
+
|
34
|
+
out = capture_output do
|
35
|
+
BarGraph.plot
|
36
|
+
end
|
37
|
+
|
38
|
+
plot_text = out.string
|
39
|
+
plot_lines = plot_text.split("\n")
|
40
|
+
assert_equal 4, plot_lines.length, 'simple plot size in number of lines'
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_bar_graph__bad_color
|
45
|
+
|
46
|
+
data = [
|
47
|
+
{:name => 'Germany', :value => 4, :color => 'red'},
|
48
|
+
{:name => 'USA', :value => 4, :color => 'blue'},
|
49
|
+
{:name => 'Ghana', :value => 1},
|
50
|
+
{:name => 'Portugal', :value => 1, :color=> 'no_such_color_in_the_world'}
|
51
|
+
]
|
52
|
+
|
53
|
+
BarGraph.data = data
|
54
|
+
|
55
|
+
out = capture_output do
|
56
|
+
BarGraph.plot
|
57
|
+
end
|
58
|
+
|
59
|
+
plot_text = out.string
|
60
|
+
plot_lines = plot_text.split("\n")
|
61
|
+
assert_equal 4, plot_lines.length, 'simple plot size in number of lines'
|
62
|
+
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/test/progressbar_test.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
|
3
|
-
class TestProgressBar < Test
|
4
|
-
include Collimator
|
5
|
-
|
6
|
-
def teardown
|
7
|
-
$stdout = STDOUT
|
8
|
-
end
|
3
|
+
class TestProgressBar < Minitest::Test
|
9
4
|
|
10
5
|
def test_progress
|
11
6
|
out = capture_output do
|
data/test/spinner_test.rb
CHANGED
@@ -1,23 +1,24 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
include Collimator
|
5
|
-
|
6
|
-
def teardown
|
7
|
-
$stdout = STDOUT
|
8
|
-
end
|
3
|
+
class TestSpinner < Minitest::Test
|
9
4
|
|
10
5
|
def test_spinner
|
11
|
-
|
6
|
+
icons = %w(- \\ | /)
|
7
|
+
|
8
|
+
spin_time = 0.5
|
12
9
|
out = capture_output do
|
13
10
|
Spinner.spin
|
14
11
|
sleep spin_time
|
15
12
|
Spinner.stop
|
16
13
|
end
|
17
14
|
|
18
|
-
length_should_be = (spin_time / 0.1) * 2
|
19
15
|
s = out.string.clone
|
20
|
-
|
16
|
+
ss = s.split("\b")
|
17
|
+
|
18
|
+
assert_equal icons[0].strip, ss[0].strip
|
19
|
+
assert_equal icons[1].strip, ss[1].strip
|
20
|
+
assert_equal icons[2].strip, ss[2].strip
|
21
|
+
assert_equal icons[3].strip, ss[3].strip
|
21
22
|
|
22
23
|
spin_time = 0.2
|
23
24
|
out = capture_output do
|
@@ -26,9 +27,10 @@ class TestProgressBar < Test::Unit::TestCase
|
|
26
27
|
Spinner.stop
|
27
28
|
end
|
28
29
|
|
29
|
-
length_should_be = (spin_time / 0.1) * 2
|
30
30
|
s = out.string.clone
|
31
|
-
|
31
|
+
ss = s.split("\b")
|
32
|
+
assert_equal icons[0], ss[0]
|
33
|
+
|
32
34
|
end
|
33
35
|
|
34
36
|
end
|
data/test/table_test.rb
CHANGED
@@ -1,21 +1,11 @@
|
|
1
|
-
|
2
|
-
require File.expand_path("../../lib/collimator", __FILE__)
|
1
|
+
require_relative 'test_helper'
|
3
2
|
|
4
|
-
|
5
|
-
require 'stringio'
|
6
|
-
require 'test_helper'
|
7
|
-
|
8
|
-
class TestTable < Test::Unit::TestCase
|
9
|
-
include Collimator
|
3
|
+
class TestTable < Minitest::Test
|
10
4
|
|
11
5
|
def setup
|
12
6
|
Table.clear_all
|
13
7
|
end
|
14
8
|
|
15
|
-
def teardown
|
16
|
-
$stdout = STDOUT
|
17
|
-
end
|
18
|
-
|
19
9
|
def test_just_table
|
20
10
|
|
21
11
|
header_text = ['head A', 'head B', 'head C']
|
data/test/test_helper.rb
CHANGED
@@ -1,13 +1,26 @@
|
|
1
|
-
require '
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/reporters'
|
3
|
+
|
2
4
|
require File.expand_path('../../lib/collimator', __FILE__)
|
3
5
|
require 'stringio'
|
4
6
|
require 'date'
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
Minitest::Reporters.use!
|
9
|
+
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new(:color => true)]
|
10
|
+
|
11
|
+
class Minitest::Test
|
12
|
+
include Collimator
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
$stdout = STDOUT
|
16
|
+
end
|
17
|
+
|
18
|
+
def capture_output
|
19
|
+
out = StringIO.new
|
20
|
+
$stdout = out
|
21
|
+
yield
|
22
|
+
return out
|
23
|
+
ensure
|
24
|
+
$stdout = STDOUT
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,77 +1,53 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: collimator
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- geordie
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
name: rdoc
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
|
-
requirements:
|
26
|
-
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 3
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
32
|
-
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
35
14
|
name: rake
|
36
|
-
|
37
|
-
|
38
|
-
none: false
|
39
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
40
17
|
- - ~>
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
hash: 63
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
- 9
|
46
|
-
- 2
|
18
|
+
- !ruby/object:Gem::Version
|
47
19
|
version: 0.9.2
|
48
20
|
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: colored
|
52
21
|
prerelease: false
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colored
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
62
34
|
type: :runtime
|
63
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
64
41
|
description: Collimator
|
65
|
-
email:
|
42
|
+
email:
|
66
43
|
- george.speake@gmail.com
|
67
44
|
executables: []
|
68
|
-
|
69
45
|
extensions: []
|
70
|
-
|
71
46
|
extra_rdoc_files: []
|
72
|
-
|
73
|
-
files:
|
47
|
+
files:
|
74
48
|
- .gitignore
|
49
|
+
- .ruby-version
|
50
|
+
- .travis.yml
|
75
51
|
- Gemfile
|
76
52
|
- Gemfile.lock
|
77
53
|
- LICENSE
|
@@ -79,49 +55,47 @@ files:
|
|
79
55
|
- README.md
|
80
56
|
- Rakefile
|
81
57
|
- collimator.gemspec
|
58
|
+
- examples/bar_graph.rb
|
82
59
|
- examples/progress_bar.rb
|
83
60
|
- examples/spinner.rb
|
84
61
|
- examples/table.rb
|
85
62
|
- lib/collimator.rb
|
63
|
+
- lib/collimator/bar_graph.rb
|
64
|
+
- lib/collimator/exceptions.rb
|
65
|
+
- lib/collimator/progress_bar.rb
|
66
|
+
- lib/collimator/spinner.rb
|
67
|
+
- lib/collimator/table.rb
|
86
68
|
- lib/collimator/version.rb
|
69
|
+
- test/bar_graph_test.rb
|
87
70
|
- test/progressbar_test.rb
|
88
71
|
- test/spinner_test.rb
|
89
72
|
- test/table_test.rb
|
90
73
|
- test/test_helper.rb
|
91
|
-
homepage:
|
74
|
+
homepage: ''
|
92
75
|
licenses: []
|
93
|
-
|
76
|
+
metadata: {}
|
94
77
|
post_install_message:
|
95
78
|
rdoc_options: []
|
96
|
-
|
97
|
-
require_paths:
|
79
|
+
require_paths:
|
98
80
|
- lib
|
99
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
none: false
|
110
|
-
requirements:
|
111
|
-
- - ">="
|
112
|
-
- !ruby/object:Gem::Version
|
113
|
-
hash: 3
|
114
|
-
segments:
|
115
|
-
- 0
|
116
|
-
version: "0"
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
117
91
|
requirements: []
|
118
|
-
|
119
92
|
rubyforge_project:
|
120
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.2.2
|
121
94
|
signing_key:
|
122
|
-
specification_version:
|
95
|
+
specification_version: 4
|
123
96
|
summary: Easy to use tabulation for displaying data in command line scripts
|
124
|
-
test_files:
|
97
|
+
test_files:
|
98
|
+
- test/bar_graph_test.rb
|
125
99
|
- test/progressbar_test.rb
|
126
100
|
- test/spinner_test.rb
|
127
101
|
- test/table_test.rb
|