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

#bar(length) ⇒ Object



35
36
37
38
39
# File 'lib/ruby-progressbar/components/bar.rb', line 35

def bar(length)
  self.length = length

  standard_complete_string
end

#bar_with_percentage(length) ⇒ Object



63
64
65
66
67
# File 'lib/ruby-progressbar/components/bar.rb', line 63

def bar_with_percentage(length)
  self.length = length

  integrated_percentage_complete_string
end

#complete_bar(length) ⇒ Object



41
42
43
44
45
# File 'lib/ruby-progressbar/components/bar.rb', line 41

def complete_bar(length)
  self.length = length

  to_s(:format => :standard)
end

#complete_bar_with_percentage(length) ⇒ Object



47
48
49
50
51
# File 'lib/ruby-progressbar/components/bar.rb', line 47

def complete_bar_with_percentage(length)
  self.length = length

  to_s(:format => :integrated_percentage)
end

#incomplete_space(length) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/ruby-progressbar/components/bar.rb', line 53

def incomplete_space(length)
  self.length = length

  if progress.unknown?
    unknown_string
  else
    incomplete_string
  end
end

#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