paul / progress_bar

A Ruby terminal progress_bar
Do What The F*ck You Want To Public License
623 stars 49 forks source link

Minimal max value & #with_progress #30

Closed zverok closed 8 years ago

zverok commented 9 years ago

Two things.

First (small): change minimal ProgressBar#max value from 1 to 0. Rationale: i constantly find myself to write code like:

bar = ProgressBar.new(some_array.count)
some_array.each do 
  # something
  bar.increment!
end

...and it works every time except when array is empty. With this small change, it will work ok with empty arrays also.

Second (huge). I want to share the code I'm constantly finding myself to add to my projects: ProgressBar::WithProgress and its (optional) inclusion to Enumerables. Just to write the things like:

(1..1000).with_progress.select{...}
# or
MyModel.dataset.with_progress.each{....}
paul commented 9 years ago

Sorry, I somehow missed this pull request. Both very good suggestions, I especially like with_progress.

Ideally, this would be two separate pull requests, but no big deal. The first is small enough I'll include it here. A couple small :neckbeard: comments inline.

paul commented 8 years ago

Sorry, I missed that you added commits to this. Thanks!

zverok commented 8 years ago

Thank you! Maybe new gem version should be released with this functionality?..