Class: ProgressBar::Components::Bar

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-progressbar/components/bar.rb

Constant Summary collapse

DEFAULT_PROGRESS_MARK =
'='.freeze
DEFAULT_REMAINDER_MARK =
' '.freeze
DEFAULT_UPA_STEPS =
['=---', '-=--', '--=-', '---='].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Bar

Returns a new instance of Bar.



17
18
19
20
21
22
23
# 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

Instance Attribute Details

#lengthObject

Returns the value of attribute length.



11
12
13
# File 'lib/ruby-progressbar/components/bar.rb', line 11

def length
  @length
end

#progressObject

Returns the value of attribute progress.



11
12
13
# File 'lib/ruby-progressbar/components/bar.rb', line 11

def progress
  @progress
end

#progress_markObject

Returns the value of attribute progress_mark.



11
12
13
# File 'lib/ruby-progressbar/components/bar.rb', line 11

def progress_mark
  @progress_mark
end

#remainder_markObject

Returns the value of attribute remainder_mark.



11
12
13
# File 'lib/ruby-progressbar/components/bar.rb', line 11

def remainder_mark
  @remainder_mark
end

#upa_stepsObject

Returns the value of attribute upa_steps.



11
12
13
# File 'lib/ruby-progressbar/components/bar.rb', line 11

def upa_steps
  @upa_steps
end

Instance Method Details

#to_s(options = { :format => :standard }) ⇒ Object



25
26
27
28
29
30
31
32
33
# 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