Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make the %w molecule only return the bar with the percentage instead …
…of including empty space
  • Loading branch information
jfelchner committed Jul 30, 2012
1 parent 11f9828 commit d4e0ea7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -133,7 +133,7 @@ The flags you can use in the format string are as follows:
* `%c`: Number of items currently completed
* `%C`: Total number of items to be completed
* `%B`: Progress bar itself
* `%w`: Bar With Integrated Percentage (eg: `|oooo 75 oooo |`)
* `%w`: Bar With Integrated Percentage (eg: `oooo 75 oooo`)
* `%m`: Mirrored progress bar (accumulates from the right)
* `%%`: A literal percent sign `%`

Expand Down
8 changes: 4 additions & 4 deletions lib/progress_bar/components/bar.rb
Expand Up @@ -31,15 +31,15 @@ def to_s(options = {:format => :standard})
mirrored? ? "#{empty_string}#{completed_string}" : "#{completed_string}#{empty_string}"
end

def integrated_percentage_complete_string
" #{percentage_completed} ".to_s.center(completed_length, progress_mark)
end

private
def standard_complete_string
progress_mark * completed_length
end

def integrated_percentage_complete_string
" #{percentage_completed} ".to_s.center(completed_length, progress_mark)
end

def completed_length
length * percentage_completed / 100
end
Expand Down
2 changes: 1 addition & 1 deletion lib/progress_bar/formatter.rb
Expand Up @@ -91,7 +91,7 @@ def complete_bar(length)

def bar_with_percentage(length)
@bar.length = length
@bar.to_s(:format => :integrated_percentage)
@bar.integrated_percentage_complete_string
end

def mirrored_bar(length)
Expand Down
6 changes: 3 additions & 3 deletions spec/progress_bar/base_spec.rb
Expand Up @@ -267,11 +267,11 @@
it 'displays the bar when passed the "%w" format flag' do
@progressbar = ProgressBar::Base.new(:output => @output, :length => 100, :starting_at => 0)

@progressbar.to_s('%w').should match /^ 0#{' ' * 98}\z/
@progressbar.to_s('%w').should match /^ 0 \z/
10.times { @progressbar.increment }
@progressbar.to_s('%w').should match /^ooo 10 ooo#{' ' * 90}\z/
@progressbar.to_s('%w').should match /^ooo 10 ooo\z/
@progressbar.decrement
@progressbar.to_s('%w').should match /^ooo 9 ooo#{' ' * 91}\z/
@progressbar.to_s('%w').should match /^ooo 9 ooo\z/
91.times { @progressbar.increment }
@progressbar.to_s('%w').should match /^#{'o' * 47} 100 #{'o' * 48}\z/
end
Expand Down

0 comments on commit d4e0ea7

Please sign in to comment.