progress
DESCRIPTION:
Class to show progress during console script run
FEATURES:
-
Progress
-
Enclosed progress
SYNOPSIS:
1000.times_with_progress('Wait') do |time| # title is optional
puts time
end
[1, 2, 3].with_progress('Wait').each do |i|
puts i
end
(1..100).with_progress('Wait').each do |i|
puts i
end
{
:a => 'a',
:b => 'b',
:c => 'c',
:d => 'd',
}.with_progress('Wait').each do |k, v|
puts "#{k} => #{v}"
end
(1..10).with_progress('Outer').map do |a|
(1..10).with_progress('Middle').map do |b|
(1..10).with_progress('Inner').map do |c|
[a, b, c]
end
end
end
symbols = []
Progress.start('Input 100 symbols', 100) do
while symbols.length < 100
input = gets.scan(/\S/)
symbols += input
Progress.step input.length
end
end
or just
symbols = []
Progress('Input 100 symbols', 100) do
while symbols.length < 100
input = gets.scan(/\S/)
symbols += input
Progress.step input.length
end
end
Note - you will get WRONG progress if you use something like this:
10.times_with_progress('A') do |time|
10.times_with_progress('B'){ … }
10.times_with_progress('C'){ … }
end
But you can use this:
10.times_with_progress('A') do |time|
Progress.step 1, 2 do
10.times_with_progress('B'){ … }
end
Progress.step 1, 2 do
10.times_with_progress('C'){ … }
end
end
Or if you know that B runs 10 times faster than C:
10.times_with_progress('A') do |time|
Progress.step 1, 11 do
10.times_with_progress('B'){ … }
end
Progress.step 10, 11 do
10.times_with_progress('C'){ … }
end
end
REQUIREMENTS:
-
ruby )))
INSTALL:
-
sudo gem install progress
LICENSE:
(The MIT License)
Copyright © 2008 toy
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.