class AnsiFormatter
def scan_and_process_string(str, substring, plain_sym, color_sym)
- 
        (Array- The processed segments.) 
Parameters:
- 
        color_sym(Symbol) -- The symbol for matching segments.
- 
        plain_sym(Symbol) -- The symbol for non-matching segments.
- 
        substring(String) -- The substring to match in the string.
- 
        str(String) -- The string to scan.
def scan_and_process_string(str, substring, plain_sym, color_sym) return string_send_color(str, plain_sym) unless substring.present? results = [] remaining_str = str.dup while remaining_str.length.positive? match_index = remaining_str.index(substring) if match_index # Process non-matching segment before the match, if any unless match_index.zero? non_matching_segment = remaining_str.slice!(0...match_index) results << string_send_color(non_matching_segment, plain_sym) end # Process the matching segment matching_segment = remaining_str.slice!(0...substring.length) results << string_send_color(matching_segment, color_sym) else # Process the remaining non-matching segment results << string_send_color(remaining_str, plain_sym) break end end results end