progress_bar 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63c44738d941428ab4348be03ab2f1744343fb7b
4
- data.tar.gz: a78ec7e3bd7e45e56ae9fb9d07d7269d3b05dbda
3
+ metadata.gz: 3103cdc1290b5ec50f1da7fbc7062081bae5c16b
4
+ data.tar.gz: 87a155b6d6d4c62892f3842061e0ffb59e9311a1
5
5
  SHA512:
6
- metadata.gz: 913cb8e575f72ff88aaf39d32e54e67abbe83ab6aa19540295b512641c898a038ad91b1b845604bb4fd19abc5cc4436e64a63ada61faf0dbaf27b982b83863d1
7
- data.tar.gz: 5a483c2f3cc1e5b41949644463c8da98ecdb9509c18ab2d117971cd72fc71589b44bdba59ec08f5c59910904e211ac66f1dd8069df9d3e17aeaf8d011d4a60d8
6
+ metadata.gz: 27f9fe545c96fcd393e0c2daf0b91fa91ca4a630f5872979845797519adfdaa46539e44b4aa1e83b46b2f2b9e9902b1b12fa57aff0fb9baec154d4e9a8a1961d
7
+ data.tar.gz: 8e841687bcfa71a84763b7827b3387dd5cb77980774762be90b5e7199b77ec127adb0d0e8b37ec4c826cae01760243444ea8930c7f1de62083c7b7cd2fcf38c3
@@ -1,16 +1,12 @@
1
1
  script: rake spec
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.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
- - rbx-2.1.1
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
+ ```
@@ -0,0 +1,4 @@
1
+
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/progress_bar/enumerable'))
3
+
4
+ p (20...34).with_progress.select{|i| sleep 0.1; (i % 2).zero?}
@@ -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 > 0
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'
@@ -0,0 +1,6 @@
1
+ require_relative '../../progress_bar'
2
+
3
+ # FIXME: should there be a better method?..
4
+ [Enumerable, Array, Hash, Range].each do |mod|
5
+ mod.send :include, ProgressBar::WithProgress
6
+ end
@@ -1,3 +1,3 @@
1
1
  class ProgressBar
2
- VERSION = "1.0.5"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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
@@ -32,7 +32,7 @@ describe 'ProgressBar arguments' do
32
32
 
33
33
  it "should raise an error when initial max is nonsense" do
34
34
  lambda {
35
- bar = ProgressBar.new(0)
35
+ bar = ProgressBar.new(-1)
36
36
  }.should raise_error(ProgressBar::ArgumentError)
37
37
  end
38
38
 
@@ -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.5
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: 2015-09-15 00:00:00.000000000 Z
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.4.5.1
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