Skip to content

Unknown Progress

Jeff Felchner edited this page Jul 13, 2016 · 2 revisions

Unknown Progress Animation

Sometimes when processing work, you don't know exactly how many items you will need to process. This might be because you're downloading a chunked file or because you're processing a set of jobs that hasn't been fully loaded yet.

In times like these, you can set total to nil and continue to increment the bar as usual. The bar will display an 'unknown' animation which will change every time you increment. This will give the appearance (by default) that the bar is processing work even though there is no "progress".

progressbar = ProgressBar.create(:starting_at => 20, :total => nil)

Will output:

Progress: |=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---|

Calling

progressbar.increment

once more will output:

Progress: |-=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=--|

ad infinitum.

At whatever point you discover the total that you will be processing, you can call:

progressbar.total = 100

And the bar will magically transform into its typical state:

Progress: |========                                                            |