Class: ProgressBar::Format::String
- Inherits:
-
String
- Object
- String
- ProgressBar::Format::String
- 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
- #bar_molecule_placeholder_length ⇒ Object
- #bar_molecules ⇒ Object
- #displayable_length ⇒ Object
- #molecules ⇒ Object
- #non_bar_molecules ⇒ Object
Instance Method Details
#bar_molecule_placeholder_length ⇒ Object
13 14 15 |
# File 'lib/ruby-progressbar/format/string.rb', line 13 def @bar_molecule_placeholder_length ||= .size * 2 end |
#bar_molecules ⇒ Object
21 22 23 |
# File 'lib/ruby-progressbar/format/string.rb', line 21 def @bar_molecules ||= molecules.select(&:bar_molecule?) end |
#displayable_length ⇒ Object
9 10 11 |
# File 'lib/ruby-progressbar/format/string.rb', line 9 def displayable_length gsub(ANSI_SGR_PATTERN, '').length end |
#molecules ⇒ Object
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_molecules ⇒ Object
17 18 19 |
# File 'lib/ruby-progressbar/format/string.rb', line 17 def @non_bar_molecules ||= molecules.select(&:non_bar_molecule?) end |