progress 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -13,7 +13,7 @@ Class to show progress during console script run
13
13
 
14
14
  == SYNOPSIS:
15
15
 
16
- 1000.times_with_progress('Wait') do |time|
16
+ 1000.times_with_progress('Wait') do |time| # title is optional
17
17
  puts time
18
18
  end
19
19
 
@@ -53,6 +53,7 @@ Class to show progress during console script run
53
53
 
54
54
  or just
55
55
 
56
+ symbols = []
56
57
  Progress('Input 100 symbols', 100) do
57
58
  while symbols.length < 100
58
59
  input = gets.scan(/\S/)
@@ -71,26 +72,22 @@ Note - you will get WRONG progress if you use something like this:
71
72
  But you can use this:
72
73
 
73
74
  10.times_with_progress('A') do |time|
74
- Progress('B,C', 2) do
75
- Progress.step do
76
- 10.times_with_progress('B'){ … }
77
- end
78
- Progress.step do
79
- 10.times_with_progress('C'){ … }
80
- end
75
+ Progress.step 1, 2 do
76
+ 10.times_with_progress('B'){ … }
77
+ end
78
+ Progress.step 1, 2 do
79
+ 10.times_with_progress('C'){ … }
81
80
  end
82
81
  end
83
82
 
84
83
  Or if you know that B runs 10 times faster than C:
85
84
 
86
85
  10.times_with_progress('A') do |time|
87
- Progress('B,C', 11) do
88
- Progress.step 1 do
89
- 10.times_with_progress('B'){ … }
90
- end
91
- Progress.step 10 do
92
- 10.times_with_progress('C'){ … }
93
- end
86
+ Progress.step 1, 11 do
87
+ 10.times_with_progress('B'){ }
88
+ end
89
+ Progress.step 10, 11 do
90
+ 10.times_with_progress('C'){ }
94
91
  end
95
92
  end
96
93
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/lib/progress.rb CHANGED
@@ -85,9 +85,9 @@ class Progress
85
85
  end
86
86
  end
87
87
 
88
- def step(steps = 1, &block)
88
+ def step(num = 1, den = 1, &block)
89
89
  if levels.last
90
- set(levels.last.current + Float(steps), &block)
90
+ set(levels.last.current + Float(num) / den, &block)
91
91
  elsif block
92
92
  block.call
93
93
  end
@@ -98,7 +98,9 @@ class Progress
98
98
  ret = if block
99
99
  levels.last.step(value - levels.last.current, &block)
100
100
  end
101
- levels.last.current = Float(value)
101
+ if levels.last
102
+ levels.last.current = Float(value)
103
+ end
102
104
  print_message
103
105
  ret
104
106
  elsif block
@@ -4,8 +4,9 @@ if defined?(ActiveRecord::Base)
4
4
  def find_each_with_progress(options = {})
5
5
  Progress.start(name.tableize, count(options)) do
6
6
  find_each do |model|
7
- yield model
8
- Progress.step
7
+ Progress.step do
8
+ yield model
9
+ end
9
10
  end
10
11
  end
11
12
  end
@@ -13,8 +14,9 @@ if defined?(ActiveRecord::Base)
13
14
  def find_in_batches_with_progress(options = {})
14
15
  Progress.start(name.tableize, count(options)) do
15
16
  find_in_batches do |batch|
16
- yield batch
17
- Progress.step batch.length
17
+ Progress.step batch.length do
18
+ yield batch
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -7,8 +7,9 @@ class Integer
7
7
  def times_with_progress(title = nil)
8
8
  Progress.start(title, self) do
9
9
  times do |i|
10
- yield i
11
- Progress.step
10
+ Progress.step do
11
+ yield i
12
+ end
12
13
  end
13
14
  end
14
15
  end
@@ -23,8 +23,9 @@ class Progress
23
23
  include Enumerable
24
24
  def each(*args, &block)
25
25
  __getobj__.each(*args) do |*yielded|
26
- block.call(*yielded)
27
- Progress.step
26
+ Progress.step do
27
+ block.call(*yielded)
28
+ end
28
29
  end
29
30
  end
30
31
 
data/progress.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{progress}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Boba Fat"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progress
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Boba Fat