class ProgressBar::Components::Bar
Constants
- DEFAULT_PROGRESS_MARK
- DEFAULT_REMAINDER_MARK
- DEFAULT_UPA_STEPS
Attributes
length[RW]
progress[RW]
progress_mark[RW]
remainder_mark[RW]
upa_steps[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 17 def initialize(options = {}) self.upa_steps = options[:unknown_progress_animation_steps] || DEFAULT_UPA_STEPS self.progress_mark = options[:progress_mark] || DEFAULT_PROGRESS_MARK self.remainder_mark = options[:remainder_mark] || DEFAULT_REMAINDER_MARK self.progress = options[:progress] self.length = options[:length] end
Public Instance Methods
to_s(options = { :format => :standard })
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 25 def to_s(options = { :format => :standard }) if progress.unknown? unknown_string elsif options[:format] == :standard "#{standard_complete_string}#{incomplete_string}" elsif options[:format] == :integrated_percentage "#{integrated_percentage_complete_string}#{incomplete_string}" end end
Private Instance Methods
bar(length)
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 51 def bar(length) self.length = length standard_complete_string end
bar_with_percentage(length)
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 85 def bar_with_percentage(length) self.length = length integrated_percentage_complete_string end
complete_bar(length)
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 57 def complete_bar(length) self.length = length to_s(:format => :standard) end
complete_bar_with_percentage(length)
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 63 def complete_bar_with_percentage(length) self.length = length to_s(:format => :integrated_percentage) end
completed_length()
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 91 def completed_length (length * progress.percentage_completed / 100).floor end
incomplete_space(length)
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 75 def incomplete_space(length) self.length = length if progress.unknown? unknown_string else incomplete_string end end
incomplete_string()
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 47 def incomplete_string remainder_mark * (length - completed_length) end
integrated_percentage_complete_string()
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 37 def integrated_percentage_complete_string return standard_complete_string if completed_length < 5 " #{progress.percentage_completed} ".to_s.center(completed_length, progress_mark) end
standard_complete_string()
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 43 def standard_complete_string progress_mark * completed_length end
unknown_progress_frame()
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 95 def unknown_progress_frame current_animation_step = progress.progress % upa_steps.size upa_steps[current_animation_step] end
unknown_string()
click to toggle source
# File lib/ruby-progressbar/components/bar.rb, line 69 def unknown_string unknown_frame_string = unknown_progress_frame * ((length / upa_steps.size) + 2) unknown_frame_string[0, length] end