Reputation: 1177
I'm trying to experiment with the open-uri and want to make a Command line interface progress bar.
I've going over the documentation for OpenURI::OpenRead where is has a progress bar code sample.
pbar = nil
open('latest.zip', 'wb') do |fo|
fo.print open('http://wordpress.org/latest.zip',
:content_length_proc => lambda { |t|
if t && 0 < t
pbar = ProgressBar.new("...", t)
pbar.file_transfer_mode
end
},
:progress_proc => lambda {|s|
pbar.set s if pbar
}).read
end
but I'm can keep getting the following error:
zip_dowloader.rb:11:in `block (2 levels) in <main>': uninitialized constant ProgressBar (NameError)
Upvotes: 0
Views: 1154
Reputation: 18784
gem install progressbar
Then add:
require 'progressbar'
to the top of your script.
Or, in a bundler-enabled project, add:
gem 'progressbar'
to your Gemfile
and run bundle install
.
Upvotes: 3