Class: ProgressBar::Format::Base
- Inherits:
-
Object
- Object
- ProgressBar::Format::Base
- Defined in:
- lib/progress_bar/format/base.rb
Instance Attribute Summary collapse
-
#molecules ⇒ Object
readonly
Returns the value of attribute molecules.
Instance Method Summary collapse
-
#initialize(format_string) ⇒ Base
constructor
A new instance of Base.
- #process(environment) ⇒ Object
Constructor Details
#initialize(format_string) ⇒ Base
Returns a new instance of Base.
6 7 8 9 |
# File 'lib/progress_bar/format/base.rb', line 6 def initialize(format_string) @format_string = format_string @molecules = parse(format_string) end |
Instance Attribute Details
#molecules ⇒ Object (readonly)
Returns the value of attribute molecules.
4 5 6 |
# File 'lib/progress_bar/format/base.rb', line 4 def molecules @molecules end |
Instance Method Details
#process(environment) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/progress_bar/format/base.rb', line 11 def process(environment) processed_string = @format_string.dup .each do |molecule| processed_string.gsub!("%#{molecule.key}", environment.send(molecule.method_name).to_s) end remaining_molecules = .size placeholder_length = remaining_molecules * 2 processed_string.gsub! '%%', '%' = environment.send(:length) - processed_string.length + placeholder_length .each do |molecule| processed_string.gsub!("%#{molecule.key}", environment.send(molecule.method_name, ).to_s) end processed_string end |