Class: Bio::TwoBit::Downloader::ProgressReporter
- Inherits:
-
Object
- Object
- Bio::TwoBit::Downloader::ProgressReporter
- Defined in:
- lib/bio/twobit/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.
103 104 105 106 107 108 109 110 111 |
# File 'lib/bio/twobit/downloader.rb', line 103 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
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/bio/twobit/downloader.rb', line 113 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 return if !done and time_current - @time_previous <= 1 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 |