Class: ProgressBar::Format::String

Inherits:
String
  • Object
show all
Defined in:
lib/ruby-progressbar/format/string.rb

Constant Summary collapse

MOLECULE_PATTERN =
/%[a-zA-Z]/.freeze
ANSI_SGR_PATTERN =
/\e\[[\d;]+m/.freeze

Instance Method Summary collapse

Instance Method Details

#bar_molecule_placeholder_lengthObject



13
14
15
# File 'lib/ruby-progressbar/format/string.rb', line 13

def bar_molecule_placeholder_length
  @bar_molecule_placeholder_length ||= bar_molecules.size * 2
end

#bar_moleculesObject



21
22
23
# File 'lib/ruby-progressbar/format/string.rb', line 21

def bar_molecules
  @bar_molecules ||= molecules.select(&:bar_molecule?)
end

#displayable_lengthObject



9
10
11
# File 'lib/ruby-progressbar/format/string.rb', line 9

def displayable_length
  gsub(ANSI_SGR_PATTERN, '').length
end

#moleculesObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby-progressbar/format/string.rb', line 25

def molecules
  @molecules ||= begin
                    molecules = []

                    scan(MOLECULE_PATTERN) do |match|
                      molecules << Molecule.new(match[1, 1])
                    end

                    molecules
                 end
end

#non_bar_moleculesObject



17
18
19
# File 'lib/ruby-progressbar/format/string.rb', line 17

def non_bar_molecules
  @non_bar_molecules ||= molecules.select(&:non_bar_molecule?)
end