progressbar_zobar 0.9.2.1 → 0.21.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb5b18eadd00416944ea4ddbbc2efc3857067781
4
+ data.tar.gz: a043ca73987bb4c2c601636213d120e4557b72e7
5
+ SHA512:
6
+ metadata.gz: 56587a8c0cb68fb7fe6472fa138de8b9924aead465612ad95f577986a58b0f78158a3e7749412984a7388df25bf0dcdc50252901e5068e896910d189db2b8ace
7
+ data.tar.gz: 17b47f96eae5bbbe7871895bb5129166b6b2a8561bdab31fa41eb862d857162989647f77e747465dc0bd25c825579c1f45b6c7dafabe2774da411cc5605840d3
data/.gitignore CHANGED
@@ -16,8 +16,10 @@ tmtags
16
16
  ## PROJECT::GENERAL
17
17
  .document
18
18
  coverage
19
+ *.gem
20
+ .rbenv-gemsets
19
21
  rdoc
20
22
  pkg
21
23
 
22
24
  ## PROJECT::SPECIFIC
23
- *.gem
25
+ /.rake_t_cache
@@ -0,0 +1 @@
1
+ 2.1.0
@@ -2,7 +2,5 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - 1.9.3
5
- - rbx-2.0
6
5
  - jruby
7
- - ruby-head
8
6
  - ree
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in ruby-duration.gemspec
4
4
  gemspec
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- progressbar_zobar (0.9.2.1)
4
+ progressbar_zobar (0.21.0.1)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
9
  bluecloth (2.1.0)
10
10
  minitest (2.2.2)
@@ -11,7 +11,7 @@ Ruby/ProgressBar is a text progress bar library for Ruby.
11
11
  It can indicate progress with percentage, a progress bar,
12
12
  and estimated remaining time.
13
13
 
14
- The latest version of Ruby/ProgressBar is available at
14
+ The latest version of Ruby/ProgressBar is available at
15
15
  ((<URL:http://namazu.org/~satoru/ruby-progressbar/>))
16
16
  .
17
17
 
@@ -29,9 +29,15 @@ The latest version of Ruby/ProgressBar is available at
29
29
  >> (1..100).each{|x| sleep(0.1); pbar.set(x)}; pbar.finish
30
30
  test: 67% |oooooooooooooooooooooooooo | ETA: 00:00:03
31
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
+
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
@@ -82,6 +91,10 @@ The latest version of Ruby/ProgressBar is available at
82
91
  --- ProgressBar#total=
83
92
  Change the progress bar's maximum value.
84
93
 
94
+ --- ProgressBar#long_running
95
+ Use adaptative running average to compute ETA, more effective for
96
+ long-running jobs or jobs whose speed may vary.
97
+
85
98
 
86
99
  ReverseProgressBar class is also available. The
87
100
  functionality is identical to ProgressBar but the direction
@@ -10,7 +10,7 @@
10
10
  #
11
11
 
12
12
  class ProgressBar
13
- VERSION = "0.9"
13
+ VERSION = "0.21.0.1"
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
@@ -53,6 +57,10 @@ private
53
57
  if @finished_p then elapsed else eta end
54
58
  end
55
59
 
60
+ def fmt_stat_for_long_run
61
+ if @finished_p then elapsed else eta_running_average end
62
+ end
63
+
56
64
  def fmt_stat_for_file_transfer
57
65
  if @finished_p then
58
66
  sprintf("%s %s %s", bytes, transfer_rate, elapsed)
@@ -91,7 +99,7 @@ private
91
99
  sec = t % 60
92
100
  min = (t / 60) % 60
93
101
  hour = t / 3600
94
- sprintf("%02d:%02d:%02d", hour, min, sec);
102
+ sprintf("% 3d:%02d:%02d", hour, min, sec);
95
103
  end
96
104
 
97
105
  # ETA stands for Estimated Time of Arrival.
@@ -101,7 +109,35 @@ private
101
109
  else
102
110
  elapsed = Time.now - @start_time
103
111
  eta = elapsed * @total / @current - elapsed;
104
- sprintf("ETA: %s", format_time(eta))
112
+ sprintf("ETA: %s", format_time(eta))
113
+ end
114
+ end
115
+
116
+ # Compute ETA with running average (better suited to long running tasks)
117
+ def eta_running_average
118
+ now = Time.now
119
+
120
+ # update throughput running average
121
+ if @total > 0 && @eta_previous && @eta_previous_time
122
+ current_elapsed = @current - @eta_previous
123
+ alpha = 0.9 ** current_elapsed
124
+ current_progress = 1.0 * current_elapsed
125
+ current_throughput = current_progress / (now - @eta_previous_time)
126
+ if @eta_throughput
127
+ @eta_throughput = @eta_throughput * alpha + current_throughput * (1-alpha)
128
+ else
129
+ @eta_throughput = current_throughput
130
+ end
131
+ end
132
+
133
+ @eta_previous = @current
134
+ @eta_previous_time = now
135
+
136
+ if @eta_throughput && @eta_throughput > 0
137
+ eta = (@total - @current) / @eta_throughput;
138
+ sprintf("ETA: %s", format_time(eta))
139
+ else
140
+ "ETA: --:--:--"
105
141
  end
106
142
  end
107
143
 
@@ -124,7 +160,7 @@ private
124
160
 
125
161
  DEFAULT_WIDTH = 80
126
162
  def get_term_width
127
- if ENV['COLUMNS'] =~ /^\d+$/
163
+ term_width = if ENV['COLUMNS'] =~ /^\d+$/
128
164
  ENV['COLUMNS'].to_i
129
165
  elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV['TERM'])) && shell_command_exists?('tput')
130
166
  `tput cols`.to_i
@@ -133,6 +169,12 @@ private
133
169
  else
134
170
  DEFAULT_WIDTH
135
171
  end
172
+
173
+ if term_width > 0
174
+ term_width
175
+ else
176
+ DEFAULT_WIDTH
177
+ end
136
178
  rescue
137
179
  DEFAULT_WIDTH
138
180
  end
@@ -203,6 +245,10 @@ public
203
245
  @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
204
246
  end
205
247
 
248
+ def long_running
249
+ @format_arguments = [:title, :percentage, :bar, :stat_for_long_run]
250
+ end
251
+
206
252
  def format= (format)
207
253
  @format = format
208
254
  end
@@ -1,12 +1,13 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/progressbar", __FILE__)
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = "progressbar_zobar"
5
- s.version = "0.9.2.1"
6
+ s.version = ProgressBar::VERSION
6
7
  s.platform = Gem::Platform::RUBY
7
8
  s.authors = ["Satoru Takabayashi", "Jose Peleteiro", 'David P Kleinschmidt']
8
9
  s.email = ["satoru@0xcc.net", "jose@peleteiro.net", 'david@kleinschmidt.name']
9
- s.homepage = "http://github.com/zobar/progressbar"
10
+ s.homepage = "http://bitbucket.org/zobar/progressbar"
10
11
  s.summary = 'Text progress bar library for Ruby, forked from progressbar.'
11
12
  s.description = "Fork of progressbar that allows changing the progress bar's title and total while still in progress."
12
13
 
@@ -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
@@ -128,10 +128,20 @@ class ProgressBarTest < Test::Unit::TestCase
128
128
  }
129
129
  pbar.finish
130
130
  end
131
+
132
+ def test_with_block
133
+ total = 100
134
+ do_make_progress_bar("test(block)", total) do |pbar|
135
+ total.times {
136
+ sleep(SleepUnit)
137
+ pbar.inc
138
+ }
139
+ end
140
+ end
131
141
  end
132
142
 
133
143
  class ReversedProgressBarTest < ProgressBarTest
134
- def do_make_progress_bar (title, total)
135
- ReversedProgressBar.new(title, total)
144
+ def do_make_progress_bar(title, total, &block)
145
+ ReversedProgressBar.new(title, total, &block)
136
146
  end
137
147
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progressbar_zobar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2.1
5
- prerelease:
4
+ version: 0.21.0.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Satoru Takabayashi
@@ -11,74 +10,92 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2011-11-28 00:00:00.000000000Z
13
+ date: 2014-03-16 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: bundler
18
- requirement: &2153885500 !ruby/object:Gem::Requirement
19
- none: false
17
+ requirement: !ruby/object:Gem::Requirement
20
18
  requirements:
21
- - - ! '>='
19
+ - - ">="
22
20
  - !ruby/object:Gem::Version
23
21
  version: 1.0.0
24
22
  type: :development
25
23
  prerelease: false
26
- version_requirements: *2153885500
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 1.0.0
27
29
  - !ruby/object:Gem::Dependency
28
30
  name: minitest
29
- requirement: &2153885040 !ruby/object:Gem::Requirement
30
- none: false
31
+ requirement: !ruby/object:Gem::Requirement
31
32
  requirements:
32
- - - ! '>='
33
+ - - ">="
33
34
  - !ruby/object:Gem::Version
34
35
  version: '0'
35
36
  type: :development
36
37
  prerelease: false
37
- version_requirements: *2153885040
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
38
43
  - !ruby/object:Gem::Dependency
39
44
  name: yard
40
- requirement: &2153884580 !ruby/object:Gem::Requirement
41
- none: false
45
+ requirement: !ruby/object:Gem::Requirement
42
46
  requirements:
43
- - - ! '>='
47
+ - - ">="
44
48
  - !ruby/object:Gem::Version
45
49
  version: '0'
46
50
  type: :development
47
51
  prerelease: false
48
- version_requirements: *2153884580
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
49
57
  - !ruby/object:Gem::Dependency
50
58
  name: rake
51
- requirement: &2153884120 !ruby/object:Gem::Requirement
52
- none: false
59
+ requirement: !ruby/object:Gem::Requirement
53
60
  requirements:
54
- - - ! '>='
61
+ - - ">="
55
62
  - !ruby/object:Gem::Version
56
63
  version: '0'
57
64
  type: :development
58
65
  prerelease: false
59
- version_requirements: *2153884120
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
60
71
  - !ruby/object:Gem::Dependency
61
72
  name: simplecov
62
- requirement: &2153883660 !ruby/object:Gem::Requirement
63
- none: false
73
+ requirement: !ruby/object:Gem::Requirement
64
74
  requirements:
65
- - - ! '>='
75
+ - - ">="
66
76
  - !ruby/object:Gem::Version
67
77
  version: 0.3.5
68
78
  type: :development
69
79
  prerelease: false
70
- version_requirements: *2153883660
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 0.3.5
71
85
  - !ruby/object:Gem::Dependency
72
86
  name: bluecloth
73
- requirement: &2153883200 !ruby/object:Gem::Requirement
74
- none: false
87
+ requirement: !ruby/object:Gem::Requirement
75
88
  requirements:
76
- - - ! '>='
89
+ - - ">="
77
90
  - !ruby/object:Gem::Version
78
91
  version: 0.3.5
79
92
  type: :development
80
93
  prerelease: false
81
- version_requirements: *2153883200
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 0.3.5
82
99
  description: Fork of progressbar that allows changing the progress bar's title and
83
100
  total while still in progress.
84
101
  email:
@@ -89,41 +106,40 @@ executables: []
89
106
  extensions: []
90
107
  extra_rdoc_files: []
91
108
  files:
92
- - .gitignore
93
- - .rvmrc
94
- - .travis.yml
109
+ - ".gitignore"
110
+ - ".ruby-version"
111
+ - ".travis.yml"
95
112
  - ChangeLog
96
113
  - Gemfile
97
114
  - Gemfile.lock
98
115
  - LICENSE
99
- - README.rd
116
+ - README.rdoc
100
117
  - Rakefile
101
118
  - lib/progressbar.rb
102
119
  - progressbar.gemspec
103
120
  - test/test.rb
104
- homepage: http://github.com/zobar/progressbar
121
+ homepage: http://bitbucket.org/zobar/progressbar
105
122
  licenses: []
123
+ metadata: {}
106
124
  post_install_message:
107
125
  rdoc_options:
108
- - --charset=UTF-8
126
+ - "--charset=UTF-8"
109
127
  require_paths:
110
128
  - lib
111
129
  required_ruby_version: !ruby/object:Gem::Requirement
112
- none: false
113
130
  requirements:
114
- - - ! '>='
131
+ - - ">="
115
132
  - !ruby/object:Gem::Version
116
133
  version: '0'
117
134
  required_rubygems_version: !ruby/object:Gem::Requirement
118
- none: false
119
135
  requirements:
120
- - - ! '>='
136
+ - - ">="
121
137
  - !ruby/object:Gem::Version
122
138
  version: 1.3.6
123
139
  requirements: []
124
140
  rubyforge_project:
125
- rubygems_version: 1.8.10
141
+ rubygems_version: 2.2.0
126
142
  signing_key:
127
- specification_version: 3
143
+ specification_version: 4
128
144
  summary: Text progress bar library for Ruby, forked from progressbar.
129
145
  test_files: []
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm 1.9.2@progressbar