Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progressbar Implementation #58

Closed
huseyin opened this issue May 25, 2021 · 1 comment
Closed

Progressbar Implementation #58

huseyin opened this issue May 25, 2021 · 1 comment

Comments

@huseyin
Copy link

huseyin commented May 25, 2021

For a while, I have been implementing an internal part of my project which is aiming to download a series of URLs that is read from a local file. Now I have a difficulty in running down along with ruby-progressbar. progress_proc option seemed to be best solution to me at first, but after a quick dive into the concept of down, I noticed that it was not as I expected. Anyone bring a solution or a workaround to my attention?

@huseyin
Copy link
Author

huseyin commented May 26, 2021

I figured out how to implement progress bar and my solution is as follows.

progressbar = ProgressBar.create(title: 'File')
url = 'https://example.com'
total_size = 0

Down.download(
  url,
  content_length_proc: ->(content_length) { total_size = content_length },
  progress_proc: lambda do |progress|
    break if progress == total_size

    progressbar.progress = (progress.to_f / total_size) * 100
  end
)

I hope this helps everybody who wants to fork. I'm closing the issue.

@huseyin huseyin closed this as completed May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant