ruby-progressbar 1.8.3 → 1.9.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: 5c76e440b5648ce692f5dc9876121e7cc96dd3af
4
- data.tar.gz: 1c0125425bb7c1e183ec2afd8d064da4238c63cf
3
+ metadata.gz: 3cd1a27db6b9c29f0440221647c623b5ab71fd7a
4
+ data.tar.gz: 8f91086c51905f925c41a3c44f97645fab0d3ad5
5
5
  SHA512:
6
- metadata.gz: c65ec7e1f2c8ff352fc80f5f655b38aadc16daf9fdadfc3bc62b025e55a6b134fe6efc23e516882cfd1e442eadf1e326f3087a9aade4f856991bee0859cf823d
7
- data.tar.gz: 41d93639c3949b40010226755058d976ea1280e771b97bd6ea4e0338257fc40dcf8b541d80f47345d9e74633c7f1d5ba680e3a2ae2fe39dbd5d93911f96cba40
6
+ metadata.gz: 9dd5f1c042df2a20a336b5cf28b68123ad19ea6e017bd3c0beff5b2c0bad54f48b5f7b8e526b3e4a134a78409d2eb5751b81c689cf55782a70c38d0a5c083e2c
7
+ data.tar.gz: da8ad7b38d1ab514a6dd3a0eb13cfe9303654a73e25069ea4c5b492180f4ccb39a08c3ddd5012ebc2c1657c7b7e78b07405908a5a9d69a1c8a4bc1d67f850b74
Binary file
data.tar.gz.sig CHANGED
@@ -1 +1,2 @@
1
- C�>��"65u��P��F��!��4��� �:�jz���eıojd�.100-�'������g��s \��M|_T�&�f�Dr���u<\4��:��g�=Ueu��x�>���)\17Sl�ߛ� ��<�I��sRc���8jGc|&��&�X�I��w`�~��%�zC�N�ȩ����Y��|A*�ť
1
+ ;��9_�JD]r74�7Bz3���v��XV�*�>�4�r��tKvT�Տ�waI��3��&��
2
+ 8D) eFY"�@nC�gjc�E��B����Ov;����q@ �a�8��E:�+�'W����ݛO�^!tO�p�P�rLo�"?i�T����Qʆ�W�@g�S�ɤ�X\V�������&l���L��bp�7���:��1u�c�-�̆� w`>�!$�������#1Sx��C�
data/README.md CHANGED
@@ -2,7 +2,7 @@ Ruby/ProgressBar
2
2
  ================================
3
3
  [![Gem Version](https://img.shields.io/gem/v/ruby-progressbar.svg)](https://rubygems.org/gems/ruby-progressbar) ![Rubygems Rank Overall](https://img.shields.io/gem/rt/ruby-progressbar.svg) ![Rubygems Rank Daily](https://img.shields.io/gem/rd/ruby-progressbar.svg) ![Rubygems Downloads](https://img.shields.io/gem/dv/ruby-progressbar/stable.svg) [![Build Status](https://img.shields.io/travis/jfelchner/ruby-progressbar/master.svg)](http://travis-ci.org/jfelchner/ruby-progressbar) [![Code Climate](https://codeclimate.com/github/jfelchner/ruby-progressbar.svg)](https://codeclimate.com/github/jfelchner/ruby-progressbar) [![Code Climate](https://codeclimate.com/github/jfelchner/ruby-progressbar/coverage.svg)](https://codeclimate.com/github/jfelchner/ruby-progressbar)
4
4
 
5
- <img src="https://www.dropbox.com/s/pe9o1yobxtubof8/ruby-progressbar-cage.png?dl=1" align="right" />
5
+ <img src="https://kompanee-public-assets.s3.amazonaws.com/readmes/ruby-progressbar-cage.png" align="right" />
6
6
 
7
7
  The **ultimate** text progress bar library for Ruby! It'll **SMASH YOU OVER THE HEAD** with a **PURE RUSH** of progress bar excitement!
8
8
 
@@ -10,12 +10,6 @@ Don't miss out on what all the kids are talking about! If you want everyone to
10
10
 
11
11
  <br><br><br>
12
12
 
13
- `progressbar` has been merged into `ruby-progressbar`!!
14
- --------------------------------
15
- As of 1.8.2 onwards, `ruby-progressbar` and `progressbar` will remain in
16
- lock-step on version numbers. *Huge* thanks to @peleteiro for giving me access
17
- to the `progressbar` rubygem.
18
-
19
13
  Full Reference
20
14
  --------------------------------
21
15
 
@@ -31,7 +25,7 @@ If you have problems, please create a [Github issue](https://github.com/jfelchne
31
25
  Credits
32
26
  --------------------------------
33
27
 
34
- ![The Kompanee](https://www.dropbox.com/s/86jfka1d6bhv8as/kompanee-text-black.png?dl=1)
28
+ ![The Kompanee](https://kompanee-public-assets.s3.amazonaws.com/readmes/kompanee-horizontal-black.png)
35
29
 
36
30
  ruby-progressbar is maintained by [The Kompanee, Ltd.](http://www.thekompanee.com)
37
31
 
@@ -40,5 +34,5 @@ The names and logos for The Kompanee are trademarks of The Kompanee, Ltd.
40
34
  License
41
35
  --------------------------------
42
36
 
43
- ruby-progressbar 1.0 is Copyright &copy; 2011-2016 The Kompanee. It is free software, and may be redistributed under the terms specified in the LICENSE file.
44
- ruby-progressbar 0.9.0 is Copyright &copy; 2008 [Satoru Takabayashi](http://namazu.org/~satoru/)
37
+ ruby-progressbar 1.0 is Copyright &copy; 2011-2018 The Kompanee. It is free software, and may be redistributed under the terms specified in the LICENSE file.
38
+ ruby-progressbar 0.9.0 is Copyright &copy; 2008 [Satoru Takabayashi](http://0xcc.net)
data/Rakefile CHANGED
File without changes
@@ -9,6 +9,7 @@ require 'ruby-progressbar/calculators/running_average'
9
9
  require 'ruby-progressbar/components'
10
10
  require 'ruby-progressbar/format'
11
11
  require 'ruby-progressbar/base'
12
+ require 'ruby-progressbar/refinements' unless RUBY_VERSION.start_with?('1.')
12
13
 
13
14
  class ProgressBar
14
15
  def self.create(*args)
@@ -37,8 +37,6 @@ class Base
37
37
  end
38
38
 
39
39
  def start(options = {})
40
- clear
41
-
42
40
  timer.start
43
41
  update_progress(:start, options)
44
42
  end
@@ -125,6 +123,30 @@ class Base
125
123
  Format::Formatter.process(@format, output.length, self)
126
124
  end
127
125
 
126
+ # rubocop:disable Metrics/AbcSize, Metrics/LineLength
127
+ def to_h
128
+ {
129
+ 'output_stream' => output.__send__(:stream),
130
+ 'length' => output.length,
131
+ 'title' => title_comp.title,
132
+ 'progress_mark' => bar.progress_mark,
133
+ 'remainder_mark' => bar.remainder_mark,
134
+ 'progress' => progressable.progress,
135
+ 'total' => progressable.total,
136
+ 'percentage' => progressable.percentage_completed_with_precision.to_f,
137
+ 'elapsed_time_in_seconds' => time.__send__(:timer).elapsed_seconds,
138
+ 'estimated_time_remaining_in_seconds' => time.__send__(:estimated_seconds_remaining),
139
+ 'base_rate_of_change' => rate.__send__(:base_rate),
140
+ 'scaled_rate_of_change' => rate.__send__(:scaled_rate),
141
+ 'unknown_progress_animation_steps' => bar.upa_steps,
142
+ 'throttle_rate' => output.__send__(:throttle).rate,
143
+ 'started?' => started?,
144
+ 'stopped?' => stopped?,
145
+ 'finished?' => finished?
146
+ }
147
+ end
148
+ # rubocop:enable Metrics/AbcSize, Metrics/LineLength
149
+
128
150
  def inspect
129
151
  "#<ProgressBar:#{progress}/#{total || 'unknown'}>"
130
152
  end
@@ -2,10 +2,12 @@ class ProgressBar
2
2
  module Calculators
3
3
  class Length
4
4
  attr_reader :length_override
5
- attr_accessor :current_length
5
+ attr_accessor :current_length,
6
+ :output
6
7
 
7
8
  def initialize(options = {})
8
9
  self.length_override = options[:length]
10
+ self.output = options[:output]
9
11
  self.current_length = nil
10
12
  end
11
13
 
@@ -37,6 +39,7 @@ class Length
37
39
 
38
40
  # This code was copied and modified from Rake, available under MIT-LICENSE
39
41
  # Copyright (c) 2003, 2004 Jim Weirich
42
+ # rubocop:disable Lint/RescueWithoutErrorClass
40
43
  def terminal_width
41
44
  return 80 unless unix?
42
45
 
@@ -45,13 +48,16 @@ class Length
45
48
  rescue
46
49
  80
47
50
  end
51
+ # rubocop:enable Lint/RescueWithoutErrorClass
48
52
 
49
53
  # rubocop:disable Lint/DuplicateMethods
50
54
  begin
51
55
  require 'io/console'
52
56
 
53
57
  def dynamic_width
54
- if IO.console
58
+ if output && output.tty?
59
+ dynamic_width_via_output_stream_object
60
+ elsif IO.console
55
61
  dynamic_width_via_io_object
56
62
  else
57
63
  dynamic_width_via_system_calls
@@ -63,6 +69,11 @@ class Length
63
69
  end
64
70
  end
65
71
 
72
+ def dynamic_width_via_output_stream_object
73
+ _rows, columns = output.winsize
74
+ columns
75
+ end
76
+
66
77
  def dynamic_width_via_io_object
67
78
  _rows, columns = IO.console.winsize
68
79
  columns
@@ -63,9 +63,11 @@ class Time
63
63
  private
64
64
 
65
65
  def estimated
66
- return OOB_UNKNOWN_TIME_TEXT if progress.unknown? || progress.none? || timer.stopped?
66
+ memo_estimated_seconds_remaining = estimated_seconds_remaining
67
67
 
68
- hours, minutes, seconds = timer.divide_seconds(estimated_seconds_remaining)
68
+ return OOB_UNKNOWN_TIME_TEXT unless memo_estimated_seconds_remaining
69
+
70
+ hours, minutes, seconds = timer.divide_seconds(memo_estimated_seconds_remaining)
69
71
 
70
72
  if hours > OOB_LIMIT_IN_HOURS && out_of_bounds_time_format
71
73
  out_of_bounds_time
@@ -87,6 +89,8 @@ class Time
87
89
  end
88
90
 
89
91
  def estimated_seconds_remaining
92
+ return if progress.unknown? || progress.none? || timer.stopped?
93
+
90
94
  (timer.elapsed_seconds * (progress.total / progress.running_average - 1)).round
91
95
  end
92
96
 
@@ -6,6 +6,7 @@ class Molecule
6
6
  :T => [:title_comp, :title],
7
7
  :c => [:progressable, :progress],
8
8
  :C => [:progressable, :total],
9
+ :u => [:progressable, :total_with_unknown_indicator],
9
10
  :p => [:percentage, :percentage],
10
11
  :P => [:percentage, :percentage_with_precision],
11
12
  :j => [:percentage, :justified_percentage],
@@ -19,7 +20,7 @@ class Molecule
19
20
  :w => [:bar, :bar_with_percentage],
20
21
  :i => [:bar, :incomplete_space],
21
22
  :r => [:rate, :rate_of_change],
22
- :R => [:rate, :rate_of_change_with_precision],
23
+ :R => [:rate, :rate_of_change_with_precision]
23
24
  }.freeze
24
25
 
25
26
  BAR_MOLECULES = %w{w B b i}.freeze
@@ -7,12 +7,17 @@ class Output
7
7
  def initialize(options = {})
8
8
  self.bar = options[:bar]
9
9
  self.stream = options[:output] || DEFAULT_OUTPUT_STREAM
10
- self.length_calculator = Calculators::Length.new(options)
11
10
  self.throttle = Throttle.new(options)
11
+ self.length_calculator = Calculators::Length.new(
12
+ :length => options[:length],
13
+ :output => stream
14
+ )
12
15
  end
13
16
 
14
17
  def self.detect(options = {})
15
- if (options[:output] || DEFAULT_OUTPUT_STREAM).tty?
18
+ if options[:output].is_a?(Class) && options[:output] <= ProgressBar::Output
19
+ options[:output].new(options)
20
+ elsif (options[:output] || DEFAULT_OUTPUT_STREAM).tty?
16
21
  Outputs::Tty.new(options)
17
22
  else
18
23
  Outputs::NonTty.new(options)
@@ -47,15 +52,17 @@ class Output
47
52
  end
48
53
  end
49
54
 
50
- def print_and_flush
51
- stream.print bar_update_string + eol
52
- stream.flush
53
- end
54
-
55
55
  protected
56
56
 
57
57
  attr_accessor :length_calculator,
58
58
  :throttle,
59
59
  :bar
60
+
61
+ private
62
+
63
+ def print_and_flush
64
+ stream.print bar_update_string + eol
65
+ stream.flush
66
+ end
60
67
  end
61
68
  end
@@ -0,0 +1,33 @@
1
+ require 'ruby-progressbar/output'
2
+
3
+ class ProgressBar
4
+ module Outputs
5
+ class Null < Output
6
+ alias refresh_with_format_change with_refresh
7
+
8
+ def clear; end
9
+ def log(_string); end
10
+ def refresh(*); end
11
+
12
+ def clear_string
13
+ ''
14
+ end
15
+
16
+ def bar_update_string
17
+ ''
18
+ end
19
+
20
+ def default_format
21
+ ''
22
+ end
23
+
24
+ def resolve_format(_format)
25
+ ''
26
+ end
27
+
28
+ def eol
29
+ ''
30
+ end
31
+ end
32
+ end
33
+ end
@@ -100,6 +100,10 @@ class Progress
100
100
  progress.nil? || total.nil?
101
101
  end
102
102
 
103
+ def total_with_unknown_indicator
104
+ total || '??'
105
+ end
106
+
103
107
  def percentage_completed_with_precision
104
108
  return 100.0 if total == 0
105
109
  return 0.0 if total.nil?
@@ -0,0 +1 @@
1
+ require 'ruby-progressbar/refinements/enumerator'
@@ -0,0 +1,25 @@
1
+ class ProgressBar
2
+ module Refinements
3
+ module Enumerator
4
+ refine ::Enumerator do
5
+ # rubocop:disable Metrics/BlockNesting
6
+ def with_progressbar(options = {}, &block)
7
+ chain = ::Enumerator.new do |yielder|
8
+ progress_bar = ProgressBar.create(options.merge(:starting_at => 0, :total => size))
9
+
10
+ each do |*args|
11
+ yielder.yield(*args).tap do
12
+ progress_bar.increment
13
+ end
14
+ end
15
+ end
16
+
17
+ return chain unless block_given?
18
+
19
+ chain.each(&block)
20
+ end
21
+ # rubocop:enable Metrics/BlockNesting
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  class ProgressBar
2
- VERSION = '1.8.3'.freeze
2
+ VERSION = '1.9.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-progressbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thekompanee
@@ -32,7 +32,7 @@ cert_chain:
32
32
  PHO6SmWDz7oWa8pdUSTTn9dNIVaxsYYuqr1HyaHdhjItQLl/4S4wZu1yqMBEwyGO
33
33
  HGJ2WkoCJ6ABU8wsO70PQd9pl1M3stScQLd3vWgPeuioBQ==
34
34
  -----END CERTIFICATE-----
35
- date: 2017-09-13 00:00:00.000000000 Z
35
+ date: 2017-09-27 00:00:00.000000000 Z
36
36
  dependencies:
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
@@ -40,14 +40,14 @@ dependencies:
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: '3.2'
43
+ version: '3.6'
44
44
  type: :development
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - "~>"
49
49
  - !ruby/object:Gem::Version
50
- version: '3.2'
50
+ version: '3.6'
51
51
  - !ruby/object:Gem::Dependency
52
52
  name: rspectacular
53
53
  requirement: !ruby/object:Gem::Requirement
@@ -119,7 +119,6 @@ files:
119
119
  - lib/ruby-progressbar.rb
120
120
  - lib/ruby-progressbar/base.rb
121
121
  - lib/ruby-progressbar/calculators/length.rb
122
- - lib/ruby-progressbar/calculators/length_spec.rb
123
122
  - lib/ruby-progressbar/calculators/running_average.rb
124
123
  - lib/ruby-progressbar/components.rb
125
124
  - lib/ruby-progressbar/components/bar.rb
@@ -134,8 +133,11 @@ files:
134
133
  - lib/ruby-progressbar/format/string.rb
135
134
  - lib/ruby-progressbar/output.rb
136
135
  - lib/ruby-progressbar/outputs/non_tty.rb
136
+ - lib/ruby-progressbar/outputs/null.rb
137
137
  - lib/ruby-progressbar/outputs/tty.rb
138
138
  - lib/ruby-progressbar/progress.rb
139
+ - lib/ruby-progressbar/refinements.rb
140
+ - lib/ruby-progressbar/refinements/enumerator.rb
139
141
  - lib/ruby-progressbar/throttle.rb
140
142
  - lib/ruby-progressbar/time.rb
141
143
  - lib/ruby-progressbar/timer.rb
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- B�%A6�L@��:_z}3Y;l��q��5j"��:��_�;Xj`IPpn�/Fx�Ƨs����Z.�pJ"���Z9 b�΄
2
- ���`j�1��r�;BT����e`~�GmY�^6��@��n�ca�1WN�p��p5�<�׿�*��m'��w8=��K��4�7��p��
1
+ ��Fr4>��,�߼a�_��ȣy���JbC|+b��o���x Pr6�U%)3�ˏ�@�� X��L4�n��.yR���ܖɒ;�����+c3����b��0NƬI)��:��$��U�)!T�sB�Fy��0�
@@ -1,9 +0,0 @@
1
- require 'rspectacular'
2
- require 'ruby-progressbar/calculators/length'
3
-
4
- class ProgressBar
5
- module Calculators
6
- describe Length do
7
- end
8
- end
9
- end