Class: ProgressBar::Components::Bar

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

Constant Summary collapse

DEFAULT_PROGRESS_MARK =
'='
DEFAULT_REMAINDER_MARK =
' '
DEFAULT_UNKNOWN_PROGRESS_ANIMATION_STEPS =
['=---', '-=--', '--=-', '---=']

Constants included from Progressable

Progressable::DEFAULT_BEGINNING_POSITION, Progressable::DEFAULT_SMOOTHING, Progressable::DEFAULT_TOTAL

Instance Attribute Summary collapse

Attributes included from Progressable

#autofinish, #finished, #progress, #running_average, #smoothing, #starting_position, #total

Instance Method Summary collapse

Methods included from Progressable

#decrement, #finish, #finished?, #increment, #percentage_completed, #percentage_completed_with_precision, #progress_made, #reset, #start, #started?

Constructor Details

#initialize(options = {}) ⇒ Bar

Returns a new instance of Bar.



15
16
17
18
19
20
21
# File 'lib/ruby-progressbar/components/bar.rb', line 15

def initialize(options = {})
  super

  self.unknown_progress_animation_steps = options[:unknown_progress_animation_steps] || DEFAULT_UNKNOWN_PROGRESS_ANIMATION_STEPS
  self.progress_mark                    = options[:progress_mark]                    || DEFAULT_PROGRESS_MARK
  self.remainder_mark                   = options[:remainder_mark]                   || DEFAULT_REMAINDER_MARK
end

Instance Attribute Details

#lengthObject

Returns the value of attribute length.



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

def length
  @length
end

#progress_markObject

Returns the value of attribute progress_mark.



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

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

#unknown_progress_animation_stepsObject

Returns the value of attribute unknown_progress_animation_steps.



13
14
15
# File 'lib/ruby-progressbar/components/bar.rb', line 13

def unknown_progress_animation_steps
  @unknown_progress_animation_steps
end

Instance Method Details

#empty_stringObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ruby-progressbar/components/bar.rb', line 39

def empty_string
  incomplete_length = (length - completed_length)

  if total.nil?
    current_animation_step = progress % unknown_progress_animation_steps.size
    animation_graphic      = unknown_progress_animation_steps[current_animation_step]

    unknown_incomplete_string = animation_graphic * ((incomplete_length / unknown_progress_animation_steps.size) + 2)

    unknown_incomplete_string[0, incomplete_length]
  else
    remainder_mark * incomplete_length
  end
end

#integrated_percentage_complete_stringObject



29
30
31
32
33
# File 'lib/ruby-progressbar/components/bar.rb', line 29

def integrated_percentage_complete_string
  return standard_complete_string if completed_length < 5

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

#standard_complete_stringObject



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

def standard_complete_string
  progress_mark * completed_length
end

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



23
24
25
26
27
# File 'lib/ruby-progressbar/components/bar.rb', line 23

def to_s(options = {:format => :standard})
  completed_string = send(:"#{options[:format]}_complete_string")

  "#{completed_string}#{empty_string}"
end