progressbar-0.21.0/ 0000755 0000041 0000041 00000000000 12247130262 014152 5 ustar www-data www-data progressbar-0.21.0/Rakefile 0000644 0000041 0000041 00000000414 12247130262 015616 0 ustar www-data www-data require 'bundler'
Bundler::GemHelper.install_tasks
task :default => :test
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/test.rb'
test.verbose = true
end
require 'yard'
YARD::Rake::YardocTask.new
progressbar-0.21.0/Gemfile.lock 0000644 0000041 0000041 00000000612 12247130262 016373 0 ustar www-data www-data PATH
remote: .
specs:
progressbar (0.21.0)
GEM
remote: https://rubygems.org/
specs:
bluecloth (2.1.0)
minitest (2.2.2)
rake (0.9.2)
simplecov (0.4.2)
simplecov-html (~> 0.4.4)
simplecov-html (0.4.5)
yard (0.7.1)
PLATFORMS
ruby
DEPENDENCIES
bluecloth (>= 0.3.5)
bundler (>= 1.0.0)
minitest
progressbar!
rake
simplecov (>= 0.3.5)
yard
progressbar-0.21.0/Gemfile 0000644 0000041 0000041 00000000142 12247130262 015442 0 ustar www-data www-data source "https://rubygems.org"
# Specify your gem's dependencies in ruby-duration.gemspec
gemspec
progressbar-0.21.0/.ruby-version 0000644 0000041 0000041 00000000006 12247130262 016613 0 ustar www-data www-data 2.0.0
progressbar-0.21.0/README.rdoc 0000644 0000041 0000041 00000007377 12247130262 015776 0 ustar www-data www-data =begin
index:Ej
= Ruby/ProgressBar: A Text Progress Bar Library for Ruby
Last Modified: 2005-05-22 00:28:04
--
Ruby/ProgressBar is a text progress bar library for Ruby.
It can indicate progress with percentage, a progress bar,
and estimated remaining time.
The latest version of Ruby/ProgressBar is available at
(())
.
== Examples
% irb --simple-prompt -r progressbar
>> pbar = ProgressBar.new("test", 100)
=> (ProgressBar: 0/100)
>> 100.times {sleep(0.1); pbar.inc}; pbar.finish
test: 100% |oooooooooooooooooooooooooooooooooooooooo| Time: 00:00:10
=> nil
>> pbar = ProgressBar.new("test", 100)
=> (ProgressBar: 0/100)
>> (1..100).each{|x| sleep(0.1); pbar.set(x)}; pbar.finish
test: 67% |oooooooooooooooooooooooooo | ETA: 00:00:03
>> ProgressBar.new("test", 100) do |pbar|
>> 100.times { sleep(0.1); pbar.inc }
>> end
test: 100% |oooooooooooooooooooooooooooooooooooooooo| Time: 00:00:10
== API
--- ProgressBar#new (title, total, out = STDERR, &block)
Display the initial progress bar and return a
ProgressBar object. ((|title|)) specifies the title,
and ((|total|)) specifies the total cost of processing.
Optional parameter ((|out|)) specifies the output IO.
The display of the progress bar is updated when one or
more percent is proceeded or one or more seconds are
elapsed from the previous display.
It also accepts a block in case you prefer not needing
to .finish the bar (see example above).
--- ProgressBar#inc (step = 1)
Increase the internal counter by ((|step|)) and update
the display of the progress bar. Display the estimated
remaining time on the right side of the bar. The counter
does not go beyond the ((|total|)).
--- ProgressBar#set (count)
Set the internal counter to ((|count|)) and update the
display of the progress bar. Display the estimated
remaining time on the right side of the bar. Raise if
((|count|)) is a negative number or a number more than
the ((|total|)).
--- ProgressBar#finish
Stop the progress bar and update the display of progress
bar. Display the elapsed time on the right side of the bar.
The progress bar always stops at 100 % by the method.
--- ProgressBar#halt
Stop the progress bar and update the display of progress
bar. Display the elapsed time on the right side of the bar.
The progress bar stops at the current percentage by the method.
--- ProgressBar#format=
Set the format for displaying a progress bar.
Default: "%-14s %3d%% %s %s".
--- ProgressBar#format_arguments=
Set the methods for displaying a progress bar.
Default: [:title, :percentage, :bar, :stat].
--- ProgressBar#file_transfer_mode
Use :stat_for_file_transfer instead of :stat to display
transfered bytes and transfer rate.
--- ProgressBar#long_running
Use adaptative running average to compute ETA, more effective for
long-running jobs or jobs whose speed may vary.
ReverseProgressBar class is also available. The
functionality is identical to ProgressBar but the direction
of the progress bar is just opposite.
== Limitations
Since the progress is calculated by the proportion to the
total cost of processing, Ruby/ProgressBar cannot be used if
the total cost of processing is unknown in advance.
Moreover, the estimation of remaining time cannot be
accurately performed if the progress does not flow uniformly.
== Download
Ruby/ProgressBar is a free software with ABSOLUTELY NO WARRANTY
under the terms of Ruby's license.
* (())
* (())
--
- (()) -
=end
progressbar-0.21.0/.travis.yml 0000644 0000041 0000041 00000000065 12247130262 016264 0 ustar www-data www-data rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- jruby
- ree
progressbar-0.21.0/lib/ 0000755 0000041 0000041 00000000000 12247130262 014720 5 ustar www-data www-data progressbar-0.21.0/lib/progressbar.rb 0000644 0000041 0000041 00000014325 12247130262 017603 0 ustar www-data www-data #
# Ruby/ProgressBar - a text progress bar library
#
# Copyright (C) 2001-2005 Satoru Takabayashi
# All rights reserved.
# This is free software with ABSOLUTELY NO WARRANTY.
#
# You can redistribute it and/or modify it under the terms
# of Ruby's license.
#
class ProgressBar
VERSION = "0.21.0"
def initialize (title, total, out = STDERR)
@title = title
@total = total
@out = out
@terminal_width = 80
@bar_mark = "o"
@current = 0
@previous = 0
@finished_p = false
@start_time = Time.now
@previous_time = @start_time
@title_width = 14
@format = "%-#{@title_width}s %3d%% %s %s"
@format_arguments = [:title, :percentage, :bar, :stat]
clear
show
if block_given?
yield(self)
finish
end
end
attr_reader :title
attr_reader :current
attr_reader :total
attr_accessor :start_time
attr_writer :bar_mark
private
def fmt_bar
bar_width = do_percentage * @terminal_width / 100
sprintf("|%s%s|",
@bar_mark * bar_width,
" " * (@terminal_width - bar_width))
end
def fmt_percentage
do_percentage
end
def fmt_stat
if @finished_p then elapsed else eta end
end
def fmt_stat_for_long_run
if @finished_p then elapsed else eta_running_average end
end
def fmt_stat_for_file_transfer
if @finished_p then
sprintf("%s %s %s", bytes, transfer_rate, elapsed)
else
sprintf("%s %s %s", bytes, transfer_rate, eta)
end
end
def fmt_title
@title[0,(@title_width - 1)] + ":"
end
def convert_bytes (bytes)
if bytes < 1024
sprintf("%6dB", bytes)
elsif bytes < 1024 * 1000 # 1000kb
sprintf("%5.1fKB", bytes.to_f / 1024)
elsif bytes < 1024 * 1024 * 1000 # 1000mb
sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
else
sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
end
end
def transfer_rate
bytes_per_second = @current.to_f / (Time.now - @start_time)
sprintf("%s/s", convert_bytes(bytes_per_second))
end
def bytes
convert_bytes(@current)
end
def format_time (t)
t = t.to_i
sec = t % 60
min = (t / 60) % 60
hour = t / 3600
sprintf("% 3d:%02d:%02d", hour, min, sec);
end
# ETA stands for Estimated Time of Arrival.
def eta
if @current == 0
"ETA: --:--:--"
else
elapsed = Time.now - @start_time
eta = elapsed * @total / @current - elapsed;
sprintf("ETA: %s", format_time(eta))
end
end
# Compute ETA with running average (better suited to long running tasks)
def eta_running_average
now = Time.now
# update throughput running average
if @total > 0 && @eta_previous && @eta_previous_time
current_elapsed = @current - @eta_previous
alpha = 0.9 ** current_elapsed
current_progress = 1.0 * current_elapsed
current_throughput = current_progress / (now - @eta_previous_time)
if @eta_throughput
@eta_throughput = @eta_throughput * alpha + current_throughput * (1-alpha)
else
@eta_throughput = current_throughput
end
end
@eta_previous = @current
@eta_previous_time = now
if @eta_throughput && @eta_throughput > 0
eta = (@total - @current) / @eta_throughput;
sprintf("ETA: %s", format_time(eta))
else
"ETA: --:--:--"
end
end
def elapsed
elapsed = Time.now - @start_time
sprintf("Time: %s", format_time(elapsed))
end
def eol
if @finished_p then "\n" else "\r" end
end
def do_percentage
if @total.zero?
100
else
@current * 100 / @total
end
end
DEFAULT_WIDTH = 80
def get_term_width
term_width = if ENV['COLUMNS'] =~ /^\d+$/
ENV['COLUMNS'].to_i
elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV['TERM'])) && shell_command_exists?('tput')
`tput cols`.to_i
elsif STDIN.tty? && shell_command_exists?('stty')
`stty size`.scan(/\d+/).map { |s| s.to_i }[1]
else
DEFAULT_WIDTH
end
if term_width > 0
term_width
else
DEFAULT_WIDTH
end
rescue
DEFAULT_WIDTH
end
def shell_command_exists?(command)
ENV['PATH'].split(File::PATH_SEPARATOR).any?{|d| File.exists? File.join(d, command) }
end
def show
arguments = @format_arguments.map {|method|
method = sprintf("fmt_%s", method)
send(method)
}
line = sprintf(@format, *arguments)
width = get_term_width
if line.length == width - 1
@out.print(line + eol)
@out.flush
elsif line.length >= width
@terminal_width = [@terminal_width - (line.length - width + 1), 0].max
if @terminal_width == 0 then @out.print(line + eol) else show end
else # line.length < width - 1
@terminal_width += width - line.length + 1
show
end
@previous_time = Time.now
end
def show_if_needed
if @total.zero?
cur_percentage = 100
prev_percentage = 0
else
cur_percentage = (@current * 100 / @total).to_i
prev_percentage = (@previous * 100 / @total).to_i
end
# Use "!=" instead of ">" to support negative changes
if cur_percentage != prev_percentage ||
Time.now - @previous_time >= 1 || @finished_p
show
end
end
public
def clear
@out.print "\r"
@out.print(" " * (get_term_width - 1))
@out.print "\r"
end
def finish
@current = @total
@finished_p = true
show
end
def finished?
@finished_p
end
def file_transfer_mode
@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
end
def long_running
@format_arguments = [:title, :percentage, :bar, :stat_for_long_run]
end
def format= (format)
@format = format
end
def format_arguments= (arguments)
@format_arguments = arguments
end
def halt
@finished_p = true
show
end
def inc (step = 1)
@current += step
@current = @total if @current > @total
show_if_needed
@previous = @current
end
def set (count)
if count < 0 || count > @total
raise "invalid count: #{count} (total: #{@total})"
end
@current = count
show_if_needed
@previous = @current
end
def inspect
"#"
end
end
class ReversedProgressBar < ProgressBar
def do_percentage
100 - super
end
end
progressbar-0.21.0/metadata.yml 0000644 0000041 0000041 00000006620 12247130262 016461 0 ustar www-data www-data --- !ruby/object:Gem::Specification
name: progressbar
version: !ruby/object:Gem::Version
version: 0.21.0
platform: ruby
authors:
- Satoru Takabayashi
- Jose Peleteiro
autorequire:
bindir: bin
cert_chain: []
date: 2013-09-13 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: bundler
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 1.0.0
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 1.0.0
- !ruby/object:Gem::Dependency
name: minitest
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: yard
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: rake
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: simplecov
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 0.3.5
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 0.3.5
- !ruby/object:Gem::Dependency
name: bluecloth
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 0.3.5
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 0.3.5
description: Ruby/ProgressBar is a text progress bar library for Ruby. It can indicate
progress with percentage, a progress bar, and estimated remaining time.
email:
- satoru@0xcc.net
- jose@peleteiro.net
executables: []
extensions: []
extra_rdoc_files: []
files:
- .gitignore
- .ruby-version
- .travis.yml
- ChangeLog
- Gemfile
- Gemfile.lock
- LICENSE
- README.rdoc
- Rakefile
- lib/progressbar.rb
- progressbar.gemspec
- test/test.rb
homepage: http://github.com/peleteiro/progressbar
licenses:
- Ruby
metadata: {}
post_install_message:
rdoc_options:
- --charset=UTF-8
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: 1.3.6
requirements: []
rubyforge_project:
rubygems_version: 2.0.6
signing_key:
specification_version: 4
summary: Ruby/ProgressBar is a text progress bar library for Ruby.
test_files: []
progressbar-0.21.0/test/ 0000755 0000041 0000041 00000000000 12247130262 015131 5 ustar www-data www-data progressbar-0.21.0/test/test.rb 0000644 0000041 0000041 00000004610 12247130262 016436 0 ustar www-data www-data require 'test/unit'
require 'progressbar'
class ProgressBarTest < Test::Unit::TestCase
SleepUnit = 0.01
def do_make_progress_bar(title, total, &block)
ProgressBar.new(title, total, &block)
end
def test_bytes
total = 1024 * 1024
pbar = do_make_progress_bar("test(bytes)", total)
pbar.file_transfer_mode
0.step(total, 2**14) {|x|
pbar.set(x)
sleep(SleepUnit)
}
pbar.finish
end
def test_clear
total = 100
pbar = do_make_progress_bar("test(clear)", total)
total.times {
sleep(SleepUnit)
pbar.inc
}
pbar.clear
puts
end
def test_halt
total = 100
pbar = do_make_progress_bar("test(halt)", total)
(total / 2).times {
sleep(SleepUnit)
pbar.inc
}
pbar.halt
end
def test_inc
total = 100
pbar = do_make_progress_bar("test(inc)", total)
total.times {
sleep(SleepUnit)
pbar.inc
}
pbar.finish
end
def test_inc_x
total = File.size("lib/progressbar.rb")
pbar = do_make_progress_bar("test(inc(x))", total)
File.new("lib/progressbar.rb").each {|line|
sleep(SleepUnit)
pbar.inc(line.length)
}
pbar.finish
end
def test_invalid_set
total = 100
pbar = do_make_progress_bar("test(invalid set)", total)
begin
pbar.set(200)
rescue RuntimeError => e
puts e.message
end
end
def test_set
total = 1000
pbar = do_make_progress_bar("test(set)", total)
(1..total).find_all {|x| x % 10 == 0}.each {|x|
sleep(SleepUnit)
pbar.set(x)
}
pbar.finish
end
def test_slow
total = 100000
pbar = do_make_progress_bar("test(slow)", total)
0.step(500, 1) {|x|
pbar.set(x)
sleep(SleepUnit)
}
pbar.halt
end
def test_total_zero
total = 0
pbar = do_make_progress_bar("test(total=0)", total)
pbar.finish
end
def test_custom_bar_mark
total = 100
pbar = do_make_progress_bar("test(custom)", total)
pbar.bar_mark = '='
total.times {
sleep(SleepUnit)
pbar.inc
}
pbar.finish
end
def test_with_block
total = 100
do_make_progress_bar("test(block)", total) do |pbar|
total.times {
sleep(SleepUnit)
pbar.inc
}
end
end
end
class ReversedProgressBarTest < ProgressBarTest
def do_make_progress_bar(title, total, &block)
ReversedProgressBar.new(title, total, &block)
end
end
progressbar-0.21.0/.gitignore 0000644 0000041 0000041 00000000253 12247130262 016142 0 ustar www-data www-data ## MAC OS
.DS_Store
## TEXTMATE
*.tmproj
tmtags
## EMACS
*~
\#*
.\#*
## VIM
*.swp
## PROJECT::GENERAL
.document
coverage
rdoc
pkg
## PROJECT::SPECIFIC
/.rake_t_cache
progressbar-0.21.0/LICENSE 0000644 0000041 0000041 00000000142 12247130262 015154 0 ustar www-data www-data Ruby/ProgressBar is a free software with ABSOLUTELY NO WARRANTY under the terms of Ruby's license. progressbar-0.21.0/progressbar.gemspec 0000644 0000041 0000041 00000002315 12247130262 020051 0 ustar www-data www-data # -*- encoding: utf-8 -*-
require File.expand_path("../lib/progressbar", __FILE__)
Gem::Specification.new do |s|
s.name = "progressbar"
s.version = ProgressBar::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Satoru Takabayashi", "Jose Peleteiro"]
s.email = ["satoru@0xcc.net", "jose@peleteiro.net"]
s.homepage = "http://github.com/peleteiro/progressbar"
s.summary = "Ruby/ProgressBar is a text progress bar library for Ruby."
s.description = "Ruby/ProgressBar is a text progress bar library for Ruby. It can indicate progress with percentage, a progress bar, and estimated remaining time."
s.license = "Ruby"
s.required_rubygems_version = ">= 1.3.6"
s.add_development_dependency "bundler", ">= 1.0.0"
s.add_development_dependency "minitest", ">= 0"
s.add_development_dependency "yard", ">= 0"
s.add_development_dependency "rake", ">= 0"
s.add_development_dependency "simplecov", ">= 0.3.5"
s.add_development_dependency "bluecloth", ">= 0.3.5"
s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
s.require_path = 'lib'
s.rdoc_options = ["--charset=UTF-8"]
end
progressbar-0.21.0/checksums.yaml.gz 0000444 0000041 0000041 00000000412 12247130262 017435 0 ustar www-data www-data qd3Re;N@"gshP*NOIw.o/|^?wzzsQMuĉMSC˸c/X%ɕ=(?VAu>Ũ YH,mNZke=0XY>C9fO$"ZZʬlo`h17by6"ٸAOUnM@ݙCrS<|4DG4
progressbar-0.21.0/ChangeLog 0000644 0000041 0000041 00000007355 12247130262 015736 0 ustar www-data www-data 2005-05-21 Satoru Takabayashi
* progressbar.rb (ProgressBar::show): Call IO#flush. Suggestted by
"Geert Fannes"
2005-01-07 Satoru Takabayashi
* progressbar.rb (ProgressBar::VERSION): Bumped version number to 0.9.
(ProgressBar::finished?): New method.
(ProgressBar::current): New attribute.
(ProgressBar::total): New attribute.
(ProgressBar::title): New attribute.
(ProgressBar::start_time): New attribute.
(ProgressBar::inspect): Change the format.
(ProgressBar::show_if_needed): Renamed from show_progress.
(ProgressBar::clear): New method.
(ProgressBar::initialize): Renamed a field: bar_width ->
terminal_width.
(ProgressBar::do_percentage): New method.
(ProgressBar::percentage): Use it.
(ReversedProgressBar): New class.
(ProgressBar::initialize): Use #clear.
(ProgressBar::fmt_bar): Ditto.
(ProgressBar::fmt_percentage): Renamed from percentage.
(ProgressBar::fmt_stat): Ditto.
(ProgressBar::fmt_stat_for_file_transfer): Ditto.
(ProgressBar::fmt_title): Ditto.
* test.rb: Use Test::Unit.
* Makefile (docs): Removed.
(progressbar.ja.html): Ditto.
(progressbar.en.html): Ditto.
(dist): New rule.
(check): New rule.
2004-02-05 Satoru Takabayashi
* Ruby/ProgressBar: Version 0.8 released!
* progressbar.rb (ProgressBar::set): Fixed the bug when caused by
the invalid count.
(ProgressBar::VERSION): Bumped version number to 0.8.
2004-01-19 Satoru Takabayashi
* Ruby/ProgressBar: Version 0.7 released!
* progressbar.rb (ProgressBar::initialize): Rename a field:
@bar_length -> @bar_width.
(ProgressBar::initialize): New field: @title_width.
(ProgressBar::title): use it.
(ProgressBar::initialize): New field: @previous_time.
(ProgressBar::show_progress): Use it and update the progress bar
if one sec. elapsed.
(ProgressBar::initialize): Call show instead of show_progress.
2004-01-16 Satoru Takabayashi
* Ruby/ProgressBar: Version 0.6 released!
* progressbar.rb (ProgressBar::show): Remove the useless condition
after "else". Thanks to Neil Spring
for the report.
(ProgressBar):
2003-07-24 Satoru Takabayashi
* Ruby/ProgressBar: Version 0.5 released!
* progressbar.rb (ProgressBar::initialize): New parameter: config.
(ProgressBar::convert_prefix_multiplier): New method.
(ProgressBar::transfer_rate): New method.
(ProgressBar::percentage): New method.
(ProgressBar::title): New method.
(ProgressBar::initialize): New fields: @bar_mark, @format,
@arguments.
(ProgressBar::get_width): New method.
(ProgressBar::stat_for_file_transfer): New method.
(ProgressBar::stat): Renamed from time.
(ProgressBar::format=): New method.
(ProgressBar::format_arguments=): New method.
(ProgressBar::convert_bytes): New method.
(ProgressBar::file_transfer_mode): New method.
2002-10-21 Satoru Takabayashi
* Ruby/ProgressBar: Version 0.4 released!
* progressbar.rb (ProgressBar::halt): New method. allowing a
"broken" ProgressBar in the event of error.
- Suggestted by Austin Ziegler
2002-01-05 Satoru Takabayashi
* Ruby/ProgressBar: Version 0.3 released!
* progressbar.rb (ProgressBar::show): Shorten @title to fall into
the format well.
2001-11-03 Satoru Takabayashi
* Ruby/ProgressBar: Version 0.2 released!
* progressbar.rb (ProgressBar::eta): Remove an unnecessary condition.
* progressbar.rb (ProgressBar::eta): Fix the return value bug.
* progressbar.rb (ProgressBar::inc): Add an optional parameter `step'.
* Ruby/ProgressBar: Version 0.1 released!