Class: ProgressBar::Components::Bar

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

Constant Summary collapse

DEFAULT_PROGRESS_MARK =
'='

Constants included from Progressable

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

Instance Attribute Summary collapse

Attributes included from Progressable

#progress, #running_average, #smoothing, #starting_position, #total

Instance Method Summary collapse

Methods included from Progressable

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

Constructor Details

#initialize(options = {}) ⇒ Bar

Returns a new instance of Bar.



11
12
13
14
15
# File 'lib/progress_bar/components/bar.rb', line 11

def initialize(options = {})
  super

  self.progress_mark   = options[:progress_mark] || DEFAULT_PROGRESS_MARK
end

Instance Attribute Details

#lengthObject

Returns the value of attribute length.



9
10
11
# File 'lib/progress_bar/components/bar.rb', line 9

def length
  @length
end

#progress_markObject

Returns the value of attribute progress_mark.



8
9
10
# File 'lib/progress_bar/components/bar.rb', line 8

def progress_mark
  @progress_mark
end

Instance Method Details

#empty_stringObject



32
33
34
# File 'lib/progress_bar/components/bar.rb', line 32

def empty_string
  ' ' * (length - completed_length)
end

#integrated_percentage_complete_stringObject



22
23
24
25
26
# File 'lib/progress_bar/components/bar.rb', line 22

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



28
29
30
# File 'lib/progress_bar/components/bar.rb', line 28

def standard_complete_string
  progress_mark * completed_length
end

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



17
18
19
20
# File 'lib/progress_bar/components/bar.rb', line 17

def to_s(options = {:format => :standard})
  completed_string = send(:"#{options[:format]}_complete_string")
  completed_string.ljust(length, ' ')
end