progress_bar 1.0.5 → 1.1.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -8
- data/README.mkd +26 -0
- data/examples/enumerable.rb +4 -0
- data/lib/progress_bar.rb +3 -1
- data/lib/progress_bar/core_ext/enumerable_with_progress.rb +6 -0
- data/lib/progress_bar/version.rb +1 -1
- data/lib/progress_bar/with_progress.rb +18 -0
- data/spec/arguments_spec.rb +1 -1
- data/spec/with_progress_spec.rb +36 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3103cdc1290b5ec50f1da7fbc7062081bae5c16b
|
4
|
+
data.tar.gz: 87a155b6d6d4c62892f3842061e0ffb59e9311a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27f9fe545c96fcd393e0c2daf0b91fa91ca4a630f5872979845797519adfdaa46539e44b4aa1e83b46b2f2b9e9902b1b12fa57aff0fb9baec154d4e9a8a1961d
|
7
|
+
data.tar.gz: 8e841687bcfa71a84763b7827b3387dd5cb77980774762be90b5e7199b77ec127adb0d0e8b37ec4c826cae01760243444ea8930c7f1de62083c7b7cd2fcf38c3
|
data/.travis.yml
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
script: rake spec
|
2
2
|
rvm:
|
3
|
-
-
|
4
|
-
- 2.
|
5
|
-
- 2.
|
3
|
+
- 2.2
|
4
|
+
- 2.3
|
5
|
+
- 2.4.0-preview3
|
6
6
|
- ruby-head
|
7
|
-
- jruby-19mode
|
8
|
-
- jruby-head
|
9
|
-
- rbx-2
|
10
7
|
|
11
8
|
matrix:
|
12
9
|
allow_failures:
|
13
10
|
- rvm:
|
14
|
-
-
|
15
|
-
- jruby-head
|
11
|
+
- 2.4.0-preview3
|
16
12
|
- ruby-head
|
data/README.mkd
CHANGED
@@ -81,6 +81,32 @@ gem install --development progress_bar
|
|
81
81
|
rspec spec/*_spec.rb
|
82
82
|
```
|
83
83
|
|
84
|
+
## Using ProgressBar on Enumerable-alikes.
|
84
85
|
|
86
|
+
If you do a lot of progresses, you can shorten your way with this:
|
85
87
|
|
88
|
+
```ruby
|
89
|
+
class Array
|
90
|
+
include ProgressBar::WithProgress
|
91
|
+
end
|
86
92
|
|
93
|
+
[1,2,3].each_with_progress{do_something}
|
94
|
+
|
95
|
+
# or any other Enumerable's methods:
|
96
|
+
|
97
|
+
(1..1000).to_a.with_progress.select{|i| (i % 2).zero?}
|
98
|
+
```
|
99
|
+
|
100
|
+
You can include `ProgressBar::WithProgress` in any class, having methods
|
101
|
+
`#count` and `#each`, like some DB datasets and so on.
|
102
|
+
|
103
|
+
If you are using progress_bar regularly on plain arrays, you may want to
|
104
|
+
do:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
require 'progress_bar/core_ext/enumerable_with_progress'
|
108
|
+
|
109
|
+
# it adds each_with_progress/with_progress to Array/Hash/Range
|
110
|
+
|
111
|
+
(1..400).with_progress.select{|i| (i % 2).zero?}
|
112
|
+
```
|
data/lib/progress_bar.rb
CHANGED
@@ -15,7 +15,7 @@ class ProgressBar
|
|
15
15
|
@meters = [:bar, :counter, :percentage, :elapsed, :eta, :rate]
|
16
16
|
|
17
17
|
@max = args.shift if args.first.is_a? Numeric
|
18
|
-
raise ArgumentError, "Max must be a positive integer" unless @max
|
18
|
+
raise ArgumentError, "Max must be a positive integer" unless @max >= 0
|
19
19
|
|
20
20
|
@meters = args unless args.empty?
|
21
21
|
|
@@ -190,3 +190,5 @@ class ProgressBar
|
|
190
190
|
end
|
191
191
|
|
192
192
|
end
|
193
|
+
|
194
|
+
require_relative 'progress_bar/with_progress'
|
data/lib/progress_bar/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
class ProgressBar
|
2
|
+
module WithProgress
|
3
|
+
def each_with_progress(&block)
|
4
|
+
bar = ProgressBar.new(count)
|
5
|
+
if block
|
6
|
+
each{|obj| yield(obj).tap{bar.increment!}}
|
7
|
+
else
|
8
|
+
Enumerator.new{|yielder|
|
9
|
+
self.each do |obj|
|
10
|
+
(yielder << obj).tap{bar.increment!}
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :with_progress, :each_with_progress
|
17
|
+
end
|
18
|
+
end
|
data/spec/arguments_spec.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
|
3
|
+
describe ProgressBar::WithProgress do
|
4
|
+
context 'with block' do
|
5
|
+
let!(:bar){ProgressBar.new}
|
6
|
+
before{
|
7
|
+
Range.send(:include, ProgressBar::WithProgress)
|
8
|
+
allow(ProgressBar).to receive(:new){|max| bar.max = max; bar}
|
9
|
+
}
|
10
|
+
it 'should set max and increment on each iteration' do
|
11
|
+
(1..20).each_with_progress do |i|
|
12
|
+
break if i > 10
|
13
|
+
end
|
14
|
+
expect(bar.max).to eq 20
|
15
|
+
expect(bar.count).to eq 10
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'without block' do
|
20
|
+
let!(:bar){ProgressBar.new}
|
21
|
+
before{
|
22
|
+
Range.send(:include, ProgressBar::WithProgress)
|
23
|
+
allow(ProgressBar).to receive(:new){|max| bar.max = max; bar}
|
24
|
+
}
|
25
|
+
it 'should give Enumerator' do
|
26
|
+
enum = (1..20).each_with_progress
|
27
|
+
expect(enum).to be_kind_of(Enumerator)
|
28
|
+
expect(bar.max).to eq 20
|
29
|
+
expect(bar.count).to eq 0
|
30
|
+
|
31
|
+
res = enum.map{|i| i + 1}
|
32
|
+
expect(res).to eq (2..21).to_a
|
33
|
+
expect(bar.count).to eq 20
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progress_bar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Sadauskas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: options
|
@@ -95,9 +95,12 @@ files:
|
|
95
95
|
- LICENSE
|
96
96
|
- README.mkd
|
97
97
|
- Rakefile
|
98
|
+
- examples/enumerable.rb
|
98
99
|
- examples/simple.rb
|
99
100
|
- lib/progress_bar.rb
|
101
|
+
- lib/progress_bar/core_ext/enumerable_with_progress.rb
|
100
102
|
- lib/progress_bar/version.rb
|
103
|
+
- lib/progress_bar/with_progress.rb
|
101
104
|
- profile/shell_every_update
|
102
105
|
- profile/shell_every_update.gif
|
103
106
|
- profile/shell_once
|
@@ -112,6 +115,7 @@ files:
|
|
112
115
|
- spec/progress_bar_spec.rb
|
113
116
|
- spec/rate_spec.rb
|
114
117
|
- spec/spec_helper.rb
|
118
|
+
- spec/with_progress_spec.rb
|
115
119
|
homepage: http://github.com/paul/progress_bar
|
116
120
|
licenses: []
|
117
121
|
metadata: {}
|
@@ -131,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
135
|
version: '0'
|
132
136
|
requirements: []
|
133
137
|
rubyforge_project: progress_bar
|
134
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.6.6
|
135
139
|
signing_key:
|
136
140
|
specification_version: 4
|
137
141
|
summary: Simple Progress Bar for output to a terminal
|
@@ -145,3 +149,4 @@ test_files:
|
|
145
149
|
- spec/progress_bar_spec.rb
|
146
150
|
- spec/rate_spec.rb
|
147
151
|
- spec/spec_helper.rb
|
152
|
+
- spec/with_progress_spec.rb
|