progressbar 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- progressbar (0.10.0)
4
+ progressbar (0.12.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.rdoc CHANGED
@@ -28,10 +28,16 @@ The latest version of Ruby/ProgressBar is available at
28
28
  => (ProgressBar: 0/100)
29
29
  >> (1..100).each{|x| sleep(0.1); pbar.set(x)}; pbar.finish
30
30
  test: 67% |oooooooooooooooooooooooooo | ETA: 00:00:03
31
+
32
+ >> ProgressBar.new("test", 100) do |pbar|
33
+ >> 100.times { sleep(0.1); pbar.inc }
34
+ >> end
35
+ test: 100% |oooooooooooooooooooooooooooooooooooooooo| Time: 00:00:10
36
+
31
37
 
32
38
  == API
33
39
 
34
- --- ProgressBar#new (title, total, out = STDERR)
40
+ --- ProgressBar#new (title, total, out = STDERR, &block)
35
41
  Display the initial progress bar and return a
36
42
  ProgressBar object. ((|title|)) specifies the title,
37
43
  and ((|total|)) specifies the total cost of processing.
@@ -41,6 +47,9 @@ The latest version of Ruby/ProgressBar is available at
41
47
  more percent is proceeded or one or more seconds are
42
48
  elapsed from the previous display.
43
49
 
50
+ It also accepts a block in case you prefer not needing
51
+ to .finish the bar (see example above).
52
+
44
53
  --- ProgressBar#inc (step = 1)
45
54
  Increase the internal counter by ((|step|)) and update
46
55
  the display of the progress bar. Display the estimated
data/lib/progressbar.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  #
11
11
 
12
12
  class ProgressBar
13
- VERSION = "0.11.0"
13
+ VERSION = "0.12.0"
14
14
 
15
15
  def initialize (title, total, out = STDERR)
16
16
  @title = title
@@ -28,6 +28,10 @@ class ProgressBar
28
28
  @format_arguments = [:title, :percentage, :bar, :stat]
29
29
  clear
30
30
  show
31
+ if block_given?
32
+ yield(self)
33
+ finish
34
+ end
31
35
  end
32
36
 
33
37
  attr_reader :title
data/test/test.rb CHANGED
@@ -4,8 +4,8 @@ require 'progressbar'
4
4
  class ProgressBarTest < Test::Unit::TestCase
5
5
  SleepUnit = 0.01
6
6
 
7
- def do_make_progress_bar (title, total)
8
- ProgressBar.new(title, total)
7
+ def do_make_progress_bar(title, total, &block)
8
+ ProgressBar.new(title, total, &block)
9
9
  end
10
10
 
11
11
  def test_bytes
@@ -106,10 +106,20 @@ class ProgressBarTest < Test::Unit::TestCase
106
106
  }
107
107
  pbar.finish
108
108
  end
109
+
110
+ def test_with_block
111
+ total = 100
112
+ do_make_progress_bar("test(block)", total) do |pbar|
113
+ total.times {
114
+ sleep(SleepUnit)
115
+ pbar.inc
116
+ }
117
+ end
118
+ end
109
119
  end
110
120
 
111
121
  class ReversedProgressBarTest < ProgressBarTest
112
- def do_make_progress_bar (title, total)
113
- ReversedProgressBar.new(title, total)
122
+ def do_make_progress_bar(title, total, &block)
123
+ ReversedProgressBar.new(title, total, &block)
114
124
  end
115
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progressbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-10 00:00:00.000000000 Z
13
+ date: 2012-11-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: 1.3.6
151
151
  requirements: []
152
152
  rubyforge_project:
153
- rubygems_version: 1.8.18
153
+ rubygems_version: 1.8.24
154
154
  signing_key:
155
155
  specification_version: 3
156
156
  summary: Ruby/ProgressBar is a text progress bar library for Ruby.