ruby-progressbar 0.11.0 → 1.0.0rc1

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 (43) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +8 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +42 -0
  7. data/Guardfile +6 -0
  8. data/LICENSE +22 -0
  9. data/README.md +229 -63
  10. data/lib/progress_bar/base.rb +166 -0
  11. data/lib/progress_bar/components.rb +5 -0
  12. data/lib/progress_bar/components/bar.rb +44 -0
  13. data/lib/progress_bar/components/elapsed_timer.rb +20 -0
  14. data/lib/progress_bar/components/estimated_timer.rb +88 -0
  15. data/lib/progress_bar/components/progressable.rb +92 -0
  16. data/lib/progress_bar/components/timer.rb +64 -0
  17. data/lib/progress_bar/depreciable.rb +121 -0
  18. data/lib/progress_bar/format.rb +2 -0
  19. data/lib/progress_bar/format/base.rb +30 -0
  20. data/lib/progress_bar/format/molecule.rb +37 -0
  21. data/lib/progress_bar/formatter.rb +109 -0
  22. data/lib/progress_bar/length_calculator.rb +53 -0
  23. data/lib/progress_bar/running_average_calculator.rb +7 -0
  24. data/lib/progress_bar/time.rb +22 -0
  25. data/lib/progress_bar/version.rb +3 -0
  26. data/lib/progressbar.rb +8 -295
  27. data/lib/ruby-progressbar.rb +19 -0
  28. data/ruby-progressbar.gemspec +44 -0
  29. data/spec/progress_bar/base_spec.rb +434 -0
  30. data/spec/progress_bar/components/bar_spec.rb +198 -0
  31. data/spec/progress_bar/components/elapsed_timer_spec.rb +79 -0
  32. data/spec/progress_bar/components/estimated_timer_spec.rb +173 -0
  33. data/spec/progress_bar/components/progressable_spec.rb +30 -0
  34. data/spec/progress_bar/format/molecule_spec.rb +22 -0
  35. data/spec/progress_bar/running_average_calculator_spec.rb +11 -0
  36. data/spec/progress_bar/time_spec.rb +51 -0
  37. data/spec/spec_helper.rb +13 -0
  38. data/spec/support/focused.rb +7 -0
  39. data/spec/support/timecop.rb +19 -0
  40. metadata +170 -19
  41. data/GPL_LICENSE +0 -340
  42. data/RUBY_LICENSE +0 -53
  43. data/test.rb +0 -247
@@ -1,53 +0,0 @@
1
- Ruby/ProgressBar is copyrighted free software by Satoru Takabayashi
2
- <satoru@namazu.org>. You can redistribute it and/or modify it under either
3
- the terms of the GPL (see GPL_LICENSE file), or the conditions below:
4
-
5
- 1. You may make and give away verbatim copies of the source form of the
6
- software without restriction, provided that you duplicate all of the
7
- original copyright notices and associated disclaimers.
8
-
9
- 2. You may modify your copy of the software in any way, provided that
10
- you do at least ONE of the following:
11
-
12
- a) place your modifications in the Public Domain or otherwise
13
- make them Freely Available, such as by posting said
14
- modifications to Usenet or an equivalent medium, or by allowing
15
- the author to include your modifications in the software.
16
-
17
- b) use the modified software only within your corporation or
18
- organization.
19
-
20
- c) rename any non-standard executables so the names do not conflict
21
- with standard executables, which must also be provided.
22
-
23
- d) make other distribution arrangements with the author.
24
-
25
- 3. You may distribute the software in object code or executable
26
- form, provided that you do at least ONE of the following:
27
-
28
- a) distribute the executables and library files of the software,
29
- together with instructions (in the manual page or equivalent)
30
- on where to get the original distribution.
31
-
32
- b) accompany the distribution with the machine-readable source of
33
- the software.
34
-
35
- c) give non-standard executables non-standard names, with
36
- instructions on where to get the original software distribution.
37
-
38
- d) make other distribution arrangements with the author.
39
-
40
- 4. You may modify and include the part of the software into any other
41
- software (possibly commercial).
42
-
43
- 5. The scripts and library files supplied as input to or produced as
44
- output from the software do not automatically fall under the
45
- copyright of the software, but belong to whomever generated them,
46
- and may be sold commercially, and may be aggregated with this
47
- software.
48
-
49
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
50
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
51
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52
- PURPOSE.
53
-
data/test.rb DELETED
@@ -1,247 +0,0 @@
1
- require 'test/unit'
2
- require File.expand_path('../lib/progressbar', __FILE__)
3
-
4
- class ProgressBarTest < Test::Unit::TestCase
5
- SleepUnit = 0.01
6
-
7
- def teardown
8
- Time.clear_stubs
9
- end
10
-
11
- def do_make_progress_bar (title, total)
12
- ProgressBar.new(title, total)
13
- end
14
-
15
- def test_bytes
16
- total = 1024 * 1024
17
- pbar = do_make_progress_bar("test(bytes)", total)
18
- pbar.file_transfer_mode
19
- 0.step(total, 2**14) {|x|
20
- pbar.set(x)
21
- sleep(SleepUnit)
22
- }
23
- pbar.finish
24
- end
25
-
26
- def test_clear
27
- total = 100
28
- pbar = do_make_progress_bar("test(clear)", total)
29
- total.times {
30
- sleep(SleepUnit)
31
- pbar.inc
32
- }
33
- pbar.clear
34
- puts
35
- end
36
-
37
- def test_halt
38
- total = 100
39
- pbar = do_make_progress_bar("test(halt)", total)
40
- (total / 2).times {
41
- sleep(SleepUnit)
42
- pbar.inc
43
- }
44
- pbar.halt
45
- end
46
-
47
- def test_inc
48
- total = 100
49
- pbar = do_make_progress_bar("test(inc)", total)
50
- total.times {
51
- sleep(SleepUnit)
52
- pbar.inc
53
- }
54
- pbar.finish
55
- end
56
-
57
- def test_inc_x
58
- total = File.size("lib/progressbar.rb")
59
- pbar = do_make_progress_bar("test(inc(x))", total)
60
- File.new("lib/progressbar.rb").each {|line|
61
- sleep(SleepUnit)
62
- pbar.inc(line.length)
63
- }
64
- pbar.finish
65
- end
66
-
67
- def test_invalid_set
68
- total = 100
69
- pbar = do_make_progress_bar("test(invalid set)", total)
70
- begin
71
- pbar.set(200)
72
- rescue RuntimeError => e
73
- puts e.message
74
- end
75
- end
76
-
77
- def test_set
78
- total = 1000
79
- pbar = do_make_progress_bar("test(set)", total)
80
- (1..total).find_all {|x| x % 10 == 0}.each {|x|
81
- sleep(SleepUnit)
82
- pbar.set(x)
83
- }
84
- pbar.finish
85
- end
86
-
87
- def test_slow
88
- total = 100000
89
- pbar = do_make_progress_bar("test(slow)", total)
90
- 0.step(500, 1) {|x|
91
- pbar.set(x)
92
- sleep(SleepUnit)
93
- }
94
- pbar.halt
95
- end
96
-
97
- def test_total_zero
98
- total = 0
99
- pbar = do_make_progress_bar("test(total=0)", total)
100
- pbar.finish
101
- end
102
-
103
- def test_alternate_bar
104
- total = 100
105
- pbar = do_make_progress_bar("test(alternate)", total)
106
- pbar.bar_mark = "="
107
- total.times {
108
- sleep(SleepUnit)
109
- pbar.inc
110
- }
111
- pbar.finish
112
- end
113
-
114
- def test_custom_bar
115
- custom_bar_class = Class.new(ProgressBar) do
116
- def title_width
117
- 20
118
- end
119
- end
120
- pbar = custom_bar_class.new('test(custom)', 100)
121
- total = 100
122
- total.times {
123
- sleep(SleepUnit)
124
- pbar.inc
125
- }
126
- pbar.finish
127
- end
128
-
129
- def test_timecop
130
- offset = 3905
131
- total = 10000
132
- pbar = do_make_progress_bar("test(timecop)", total)
133
- Time.stub(:now_without_mock_time, lambda { Time.now_without_stubbing })
134
- Time.stub(:now, lambda { Time.now_without_stubbing - offset })
135
- 0.step(500, 1) {|x|
136
- Time.stub(:now, lambda { Time.now_without_stubbing + offset }) if x == 250
137
- sleep(SleepUnit)
138
- pbar.set(x)
139
- }
140
- pbar.halt
141
- end
142
-
143
- def test_delorean
144
- offset = 3905
145
- total = 10000
146
- pbar = do_make_progress_bar("test(delorean)", total)
147
- Time.stub(:now_without_delorean, lambda { Time.now_without_stubbing })
148
- Time.stub(:now, lambda { Time.now_without_stubbing - offset })
149
- 0.step(500, 1) {|x|
150
- Time.stub(:now, lambda { Time.now_without_stubbing + offset }) if x == 250
151
- sleep(SleepUnit)
152
- pbar.set(x)
153
- }
154
- pbar.halt
155
- end
156
-
157
- def test_vary
158
- total = 5000
159
- pbar = do_make_progress_bar("test(vary)", total)
160
- 0.step(500, 1) {|x|
161
- pbar.set(x)
162
- sleep(SleepUnit)
163
- }
164
- 500.step(2000, 3) {|x|
165
- pbar.set(x)
166
- sleep(SleepUnit)
167
- }
168
- 500.times {
169
- pbar.set(2000)
170
- sleep(SleepUnit)
171
- }
172
- 2000.step(1500, -1) {|x|
173
- pbar.set(x)
174
- sleep(SleepUnit)
175
- }
176
- 1500.step(5000, 5) {|x|
177
- pbar.set(x)
178
- sleep(SleepUnit)
179
- }
180
- pbar.halt
181
- end
182
-
183
- class StubbedTtyProgressBar < ProgressBar
184
- def tty?; false; end
185
- end
186
-
187
- def test_non_tty
188
- total = 1024 * 1024
189
- pbar = StubbedTtyProgressBar.new("non-tty compatible", total)
190
- 0.step(total, 2**14) {|x|
191
- pbar.set(x)
192
- sleep(SleepUnit)
193
- }
194
- pbar.finish
195
- end
196
- end
197
-
198
- class ReversedProgressBarTest < ProgressBarTest
199
- def do_make_progress_bar (title, total)
200
- ReversedProgressBar.new(title, total)
201
- end
202
- end
203
-
204
- module Stubbing
205
- def stub(method_name, value=nil)
206
- stubs[method_name.to_sym] = value
207
- end
208
-
209
- def clear_stubs
210
- stubs.clear
211
- end
212
-
213
- def respond_to?(method_name, include_private=false)
214
- has_stub?(method_name) || super
215
- end
216
-
217
- def method_missing(method_name, *args, &blk)
218
- has_stub?(method_name) ? invoke_stub(method_name) : super
219
- end
220
-
221
- private
222
-
223
- def stubs
224
- @stubs ||= {}
225
- end
226
-
227
- def has_stub?(method_name)
228
- stubs.keys.include? method_name.to_sym
229
- end
230
-
231
- def invoke_stub(method_name)
232
- stub = stubs[method_name]
233
- stub.respond_to?(:call) ? stub.call : stub
234
- end
235
- end
236
-
237
- class Time
238
- extend Stubbing
239
-
240
- class << self
241
- alias_method :now_without_stubbing, :now
242
-
243
- def now
244
- has_stub?(:now) ? invoke_stub(:now) : now_without_stubbing
245
- end
246
- end
247
- end