infobar 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Infobar::Number do
4
+ it 'can convert number into string' do
5
+ expect(described_class.new(Math::PI).to_s).to start_with '3.141'
6
+ end
7
+
8
+ it 'can convert number into string for format' do
9
+ expect(described_class.new(Math::PI, format: '%.3f').to_s).to eq '3.142'
10
+ end
11
+ end
12
+
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Infobar::Spinner do
4
+ it 'spins according to count' do
5
+ spinner = described_class.new
6
+ expect(spinner.spin(0).to_s).to eq ?|
7
+ expect(spinner.spin(1).to_s).to eq ?/
8
+ expect(spinner.spin(2).to_s).to eq ?–
9
+ expect(spinner.spin(3).to_s).to eq ?\\
10
+ expect(spinner.spin(4).to_s).to eq ?|
11
+ end
12
+
13
+ it 'supports different frames' do
14
+ spinner = described_class.new(%w[ . o O ])
15
+ expect(spinner.spin(0).to_s).to eq ?.
16
+ expect(spinner.spin(1).to_s).to eq ?o
17
+ expect(spinner.spin(2).to_s).to eq ?O
18
+ expect(spinner.spin(3).to_s).to eq ?.
19
+ end
20
+
21
+ it 'supports different predefined frames' do
22
+ expect do
23
+ described_class.new(:fuck_it)
24
+ end.to raise_error(KeyError)
25
+ spinner = described_class.new(:cross)
26
+ expect(spinner.spin(0).to_s).to eq ?+
27
+ expect(spinner.spin(1).to_s).to eq ?×
28
+ expect(spinner.spin(2).to_s).to eq ?+
29
+ end
30
+
31
+ it 'can spin randomly' do
32
+ srand 1
33
+ spinner = described_class.new(:braille7)
34
+ expect(spinner.spin(:random).to_s).to eq ?⣟
35
+ expect(spinner.spin(:random).to_s).to eq ?⢿
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Infobar::Timer do
4
+ let :timer do
5
+ described_class.new
6
+ end
7
+
8
+ it 'has default average time of 0.0' do
9
+ expect(timer.average_time).to eq 0.0
10
+ end
11
+
12
+ it 'has default rate of 0.0' do
13
+ expect(timer.rate).to eq 0.0
14
+ end
15
+
16
+ it 'can be added to' do
17
+ now = Time.now
18
+ timer.add(now, 2)
19
+ expect(timer.average_time).to eq 0.0
20
+ expect(timer.rate).to eq 0.0
21
+ expect(timer.n).to eq 1
22
+ timer.add(now + 2, 4)
23
+ expect(timer.average_time).to be_within(1e-3).of(3.0 / 4)
24
+ expect(timer.rate).to be_within(1e-3).of(4 / 3.0)
25
+ expect(timer.n).to eq 2
26
+ timer.add(now + 3, 1)
27
+ expect(timer.average_time).to be_within(1e-3).of(0.8333)
28
+ expect(timer.rate).to be_within(1e-3).of(1 / 0.8333)
29
+ expect(timer.n).to eq 3
30
+ end
31
+ end
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+
3
+ describe Infobar do
4
+ after do
5
+ infobar.reset
6
+ infobar.show = true
7
+ end
8
+
9
+ it 'can be called with total' do
10
+ expect(infobar).not_to receive(:update)
11
+ Infobar(total: 10)
12
+ expect(infobar.counter.total).to eq 10
13
+ end
14
+
15
+ it 'can be called and update instantly' do
16
+ expect(infobar).to receive(:update).and_call_original
17
+ Infobar(total: 10, update: true)
18
+ end
19
+
20
+ it 'can be called via toplevel method' do
21
+ Infobar(total: 10)
22
+ expect(infobar.counter.total).to eq 10
23
+ end
24
+
25
+ it 'can be progressing' do
26
+ Infobar(total: 10)
27
+ expect(infobar.counter.current).to eq 0
28
+ expect(infobar.progress).to eq infobar
29
+ expect(infobar.counter.current).to eq 1
30
+ end
31
+
32
+ it 'can be progressing with unary +' do
33
+ Infobar(total: 10)
34
+ expect(infobar.counter.current).to eq 0
35
+ expect(+infobar).to eq infobar
36
+ expect(infobar.counter.current).to eq 1
37
+ end
38
+
39
+ it 'can be progressing by n' do
40
+ Infobar(total: 10)
41
+ expect(infobar.counter.current).to eq 0
42
+ expect(infobar.progress(by: 3)).to eq infobar
43
+ expect(infobar.counter.current).to eq 3
44
+ end
45
+
46
+ it 'can be progressing by n with binary +' do
47
+ infobar = Infobar(total: 10)
48
+ expect(infobar.counter.current).to eq 0
49
+ expect(infobar + 3).to eq infobar
50
+ expect(infobar.counter.current).to eq 3
51
+ expect(2 + infobar).to eq infobar
52
+ expect(infobar.counter.current).to eq 5
53
+ expect(infobar += 2).to eq infobar # only for variables
54
+ expect(infobar.counter.current).to eq 7
55
+ end
56
+
57
+ it 'can be progressing with <<' do
58
+ Infobar(total: 10)
59
+ expect(infobar.counter.current).to eq 0
60
+ expect(infobar << 1).to eq infobar
61
+ expect(infobar.counter.current).to eq 1
62
+ end
63
+
64
+ it 'can be progressing by n push/add' do
65
+ Infobar(total: 10)
66
+ expect(infobar.counter.current).to eq 0
67
+ expect(infobar.push(1, 2)).to eq infobar
68
+ expect(infobar.counter.current).to eq 2
69
+ expect(infobar.add(1, 2)).to eq infobar
70
+ expect(infobar.counter.current).to eq 4
71
+ end
72
+
73
+ it 'can be reset via ~' do
74
+ expect(infobar).to receive(:reset).twice
75
+ ~infobar
76
+ end
77
+
78
+ it 'finishes by progress' do
79
+ Infobar(total: 10)
80
+ expect(infobar).not_to be_finished
81
+ infobar + 10
82
+ expect(infobar).to be_finished
83
+ end
84
+
85
+ it 'can avoid finishing by progress' do
86
+ Infobar(total: 10)
87
+ expect(infobar).not_to be_finished
88
+ infobar.progress(by: 10, finish: false)
89
+ expect(infobar).not_to be_finished
90
+ end
91
+
92
+ it 'can sent specific message if finished by progress' do
93
+ Infobar(total: 10)
94
+ expect(infobar).not_to be_finished
95
+ expect(infobar).to receive(:finish).with(message: 'hello').
96
+ and_call_original
97
+ infobar.progress(by: 10, finish: 'hello')
98
+ expect(infobar).to be_finished
99
+ end
100
+
101
+ it 'can be finished eplicitely' do
102
+ Infobar(total: 10)
103
+ expect(infobar).not_to be_finished
104
+ message = Infobar::Message.new(format: 'hello')
105
+ expect(infobar.display).to receive(:update).with(
106
+ message: message,
107
+ force: true,
108
+ progressed: 0.0
109
+ ).and_call_original
110
+ infobar.finish message: message
111
+ expect(infobar).to be_finished
112
+ end
113
+
114
+ it 'can output newline' do
115
+ expect(infobar.display).to receive(:newline)
116
+ infobar.newline
117
+ end
118
+
119
+ it 'can be hidden' do
120
+ expect(infobar.display.output).not_to receive(:<<)
121
+ infobar.show = false
122
+ infobar.newline
123
+ end
124
+
125
+ it 'can set a new style' do
126
+ Infobar(total: 10, style: { done_fill: ?X })
127
+ output = ''
128
+ infobar.display.output = output
129
+ infobar.progress(force: true)
130
+ expect(output).to include 'X'
131
+ end
132
+
133
+ it 'can set display frequency' do
134
+ expect(infobar.display.frequency.duration).to be_within(3e-3).of 0.05
135
+ infobar.display.frequency = 0.1
136
+ expect(infobar.display.frequency.duration).to be_within(3e-3).of 0.1
137
+ end
138
+
139
+ it 'can interpret size on an object' do
140
+ [ 1, 2, 3 ].with_infobar
141
+ expect(infobar.counter.total).to eq 3
142
+ end
143
+
144
+ it 'can interpret size on an object' do
145
+ '🇩🇪'.with_infobar(total: :bytesize)
146
+ expect(infobar.counter.total).to eq 8
147
+ end
148
+ end
@@ -0,0 +1,12 @@
1
+ if ENV['START_SIMPLECOV'].to_i == 1
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "#{File.basename(File.dirname(__FILE__))}/"
5
+ end
6
+ end
7
+ require 'rspec'
8
+ begin
9
+ require 'byebug'
10
+ rescue LoadError
11
+ end
12
+ require 'infobar'
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infobar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Florian Frank
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gem_hadar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.9.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.9.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: tins
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 1.13.2
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '1.0'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 1.13.2
89
+ - !ruby/object:Gem::Dependency
90
+ name: term-ansicolor
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.4'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.4'
103
+ - !ruby/object:Gem::Dependency
104
+ name: complex_config
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.10'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.10'
117
+ description: This gem displays progress of computations and additional information
118
+ to the terminal.
119
+ email: flori@ping.de
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files:
123
+ - README.md
124
+ - lib/infobar.rb
125
+ - lib/infobar/counter.rb
126
+ - lib/infobar/display.rb
127
+ - lib/infobar/duration.rb
128
+ - lib/infobar/fancy_interface.rb
129
+ - lib/infobar/frequency.rb
130
+ - lib/infobar/input_output.rb
131
+ - lib/infobar/message.rb
132
+ - lib/infobar/number.rb
133
+ - lib/infobar/spinner.rb
134
+ - lib/infobar/timer.rb
135
+ - lib/infobar/version.rb
136
+ files:
137
+ - ".gitignore"
138
+ - ".rspec"
139
+ - ".utilsrc"
140
+ - Gemfile
141
+ - README.md
142
+ - Rakefile
143
+ - TODO.md
144
+ - VERSION
145
+ - infobar.gemspec
146
+ - lib/infobar.rb
147
+ - lib/infobar/counter.rb
148
+ - lib/infobar/display.rb
149
+ - lib/infobar/duration.rb
150
+ - lib/infobar/fancy_interface.rb
151
+ - lib/infobar/frequency.rb
152
+ - lib/infobar/input_output.rb
153
+ - lib/infobar/message.rb
154
+ - lib/infobar/number.rb
155
+ - lib/infobar/spinner.rb
156
+ - lib/infobar/timer.rb
157
+ - lib/infobar/version.rb
158
+ - spec/config/infobar.yml
159
+ - spec/infobar/config_spec.rb
160
+ - spec/infobar/counter_spec.rb
161
+ - spec/infobar/display_spec.rb
162
+ - spec/infobar/duration_spec.rb
163
+ - spec/infobar/frequency_spec.rb
164
+ - spec/infobar/input_output_spec.rb
165
+ - spec/infobar/message_spec.rb
166
+ - spec/infobar/number_spec.rb
167
+ - spec/infobar/spinner_spec.rb
168
+ - spec/infobar/timer_spec.rb
169
+ - spec/infobar_spec.rb
170
+ - spec/spec_helper.rb
171
+ homepage: http://flori.github.com/infobar
172
+ licenses: []
173
+ metadata: {}
174
+ post_install_message:
175
+ rdoc_options:
176
+ - "--title"
177
+ - Infobar
178
+ - "--main"
179
+ - README.md
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '2.3'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.6.8
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Gem to display information about computations.
198
+ test_files:
199
+ - spec/infobar/config_spec.rb
200
+ - spec/infobar/counter_spec.rb
201
+ - spec/infobar/display_spec.rb
202
+ - spec/infobar/duration_spec.rb
203
+ - spec/infobar/frequency_spec.rb
204
+ - spec/infobar/input_output_spec.rb
205
+ - spec/infobar/message_spec.rb
206
+ - spec/infobar/number_spec.rb
207
+ - spec/infobar/spinner_spec.rb
208
+ - spec/infobar/timer_spec.rb
209
+ - spec/infobar_spec.rb
210
+ - spec/spec_helper.rb