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]/
ANSI_SGR_PATTERN =
/\e\[[\d;]+m/

Instance Method Summary collapse

Instance Method Details

#bar_molecule_placeholder_lengthObject



11
12
13
# File 'lib/ruby-progressbar/format/string.rb', line 11

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

#bar_moleculesObject



19
20
21
# File 'lib/ruby-progressbar/format/string.rb', line 19

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

#displayable_lengthObject



7
8
9
# File 'lib/ruby-progressbar/format/string.rb', line 7

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

#moleculesObject



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

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

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

                    molecules
                  end
end

#non_bar_moleculesObject



15
16
17
# File 'lib/ruby-progressbar/format/string.rb', line 15

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