Class: Datasets::Downloader::ProgressReporter
- Inherits:
-
Object
- Object
- Datasets::Downloader::ProgressReporter
- Defined in:
- lib/datasets/downloader.rb
Instance Method Summary collapse
-
#initialize(base_name, size_max) ⇒ ProgressReporter
constructor
A new instance of ProgressReporter.
- #report(size_current) ⇒ Object
Constructor Details
#initialize(base_name, size_max) ⇒ ProgressReporter
Returns a new instance of ProgressReporter.
70 71 72 73 74 75 76 77 78 |
# File 'lib/datasets/downloader.rb', line 70 def initialize(base_name, size_max) @base_name = base_name @size_max = size_max @time_previous = Time.now @size_previous = 0 @need_report = ($stderr == STDERR and $stderr.tty?) end |
Instance Method Details
#report(size_current) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/datasets/downloader.rb', line 80 def report(size_current) return unless @need_report return if @size_max.nil? return unless foreground? done = (size_current == @size_max) time_current = Time.now if not done and time_current - @time_previous <= 1 return end read_bytes = size_current - @size_previous throughput = read_bytes.to_f / (time_current - @time_previous) @time_previous = time_current @size_previous = size_current = (size_current, throughput) $stderr.print("\r#{}") if $stderr.puts if done end |